DATACMNS-993 - Clean up class loader hacking in tests.
ClassLoaderRule with @ClassLoaderConfiguration allows easy creation FilteringClassLoader. Changed usage pattern of ClassUtils.isPresent(…) in order to ease testing. Copied the ShadowingClassloader from SpringFramework to get a constructor that doesn't shadow anything by default. Original pull request: #202.
This commit is contained in:
committed by
Oliver Gierke
parent
562b6665a3
commit
65734739bd
@@ -78,15 +78,22 @@ public @interface EnableSpringDataWebSupport {
|
||||
* https://jira.springsource.org/browse/SPR-10565).
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
static class SpringDataWebConfigurationImportSelector implements ImportSelector, ResourceLoaderAware {
|
||||
|
||||
// Don't make final to allow test cases faking this to false
|
||||
private static boolean HATEOAS_PRESENT = ClassUtils.isPresent("org.springframework.hateoas.Link", null);
|
||||
private static boolean JACKSON_PRESENT = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", null);
|
||||
|
||||
private Environment environment;
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.context.EnvironmentAware#setEnvironment(org.springframework.core.env.Environment)
|
||||
*/
|
||||
@Override
|
||||
public void setEnvironment(Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.context.ResourceLoaderAware#setResourceLoader(org.springframework.core.io.ResourceLoader)
|
||||
@@ -105,10 +112,11 @@ public @interface EnableSpringDataWebSupport {
|
||||
|
||||
List<String> imports = new ArrayList<>();
|
||||
|
||||
imports.add(HATEOAS_PRESENT ? HateoasAwareSpringDataWebConfiguration.class.getName()
|
||||
imports.add(ClassUtils.isPresent("org.springframework.hateoas.Link", resourceLoader.getClassLoader())
|
||||
? HateoasAwareSpringDataWebConfiguration.class.getName()
|
||||
: SpringDataWebConfiguration.class.getName());
|
||||
|
||||
if (JACKSON_PRESENT) {
|
||||
if (ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", resourceLoader.getClassLoader())) {
|
||||
imports.addAll(
|
||||
SpringFactoriesLoader.loadFactoryNames(SpringDataJacksonModules.class, resourceLoader.getClassLoader()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user