Browse Source
If no QuerydslBinderCustomizer is configured on @QuerydslPredicate specifically, we now also consider the domain types repository as candidate for binding customization. The lookup algorithm for explicitly configured customizers has been refined to try to find a bean in the BeanFactory first, resorting to on-the-fly creation eventually. QuerydslPredicateArgumentResolver is now registered as a lazily initialized bean and its usage is guarded by checking presence of Querydsl itself. The according test needs to do some reflection in order to stay out of trouble when types are loaded by different class loaders required to hide certain types. Original pull request: #132.pull/133/head
4 changed files with 233 additions and 8 deletions
@ -0,0 +1,105 @@
@@ -0,0 +1,105 @@
|
||||
/* |
||||
* Copyright 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.web.config; |
||||
|
||||
import static org.junit.Assert.*; |
||||
import static org.springframework.test.util.ReflectionTestUtils.*; |
||||
|
||||
import java.net.URLClassLoader; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import org.junit.Test; |
||||
import org.springframework.beans.BeansException; |
||||
import org.springframework.beans.factory.ObjectFactory; |
||||
import org.springframework.core.convert.ConversionService; |
||||
import org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver; |
||||
import org.springframework.instrument.classloading.ShadowingClassLoader; |
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; |
||||
|
||||
/** |
||||
* @author Christoph Strobl |
||||
*/ |
||||
public class SpringDataWebConfigurationUnitTests { |
||||
|
||||
/** |
||||
* @see DATACMNS-669 |
||||
*/ |
||||
@Test |
||||
public void shouldNotAddQuerydslPredicateArgumentResolverWhenQuerydslNotPresent() throws ClassNotFoundException, |
||||
InstantiationException, IllegalAccessException { |
||||
|
||||
ClassLoader classLoader = initClassLoader(); |
||||
|
||||
Object config = classLoader.loadClass("org.springframework.data.web.config.SpringDataWebConfiguration") |
||||
.newInstance(); |
||||
|
||||
setField(config, "context", |
||||
classLoader.loadClass("org.springframework.web.context.support.GenericWebApplicationContext").newInstance()); |
||||
setField( |
||||
config, |
||||
"conversionService", |
||||
classLoader.loadClass( |
||||
"org.springframework.data.web.config.SpringDataWebConfigurationUnitTests$ObjectFactoryImpl").newInstance()); |
||||
|
||||
List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver>(); |
||||
|
||||
invokeMethod(config, "addArgumentResolvers", argumentResolvers); |
||||
|
||||
for (Object resolver : argumentResolvers) { |
||||
if (resolver instanceof QuerydslPredicateArgumentResolver) { |
||||
fail("QuerydslPredicateArgumentResolver should not be present when Querydsl not on path"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private ClassLoader initClassLoader() { |
||||
|
||||
ClassLoader classLoader = new ShadowingClassLoader(URLClassLoader.getSystemClassLoader()) { |
||||
|
||||
@Override |
||||
public Class<?> loadClass(String name) throws ClassNotFoundException { |
||||
|
||||
if (name.startsWith("com.mysema")) { |
||||
throw new ClassNotFoundException(); |
||||
} |
||||
|
||||
return super.loadClass(name); |
||||
} |
||||
|
||||
@Override |
||||
protected Class<?> findClass(String name) throws ClassNotFoundException { |
||||
|
||||
if (name.startsWith("com.mysema")) { |
||||
throw new ClassNotFoundException(); |
||||
} |
||||
|
||||
return super.findClass(name); |
||||
} |
||||
}; |
||||
|
||||
return classLoader; |
||||
} |
||||
|
||||
public static class ObjectFactoryImpl implements ObjectFactory<ConversionService> { |
||||
|
||||
@Override |
||||
public ConversionService getObject() throws BeansException { |
||||
return null; |
||||
} |
||||
|
||||
} |
||||
} |
||||
Loading…
Reference in new issue