Browse Source

DATACMNS-987 - Polishing.

Remove unused Querydsl tests. Add author. Reformat code. Extend Javadoc.
pull/194/head
Mark Paluch 9 years ago committed by Oliver Gierke
parent
commit
f453130569
  1. 9
      src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java
  2. 76
      src/test/java/org/springframework/data/web/config/SpringDataWebConfigurationIntegrationTests.java

9
src/main/java/org/springframework/data/web/config/SpringDataWebConfiguration.java

@ -44,9 +44,10 @@ import com.fasterxml.jackson.databind.ObjectMapper; @@ -44,9 +44,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
/**
* Configuration class to register {@link PageableHandlerMethodArgumentResolver},
* {@link SortHandlerMethodArgumentResolver} and {@link DomainClassConverter}.
*
*
* @since 1.6
* @author Oliver Gierke
* @author Jens Schauder
*/
@Configuration
public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter {
@ -72,7 +73,7 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter { @@ -72,7 +73,7 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter {
return new SortHandlerMethodArgumentResolver();
}
/*
/*
* (non-Javadoc)
* @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter#addFormatters(org.springframework.format.FormatterRegistry)
*/
@ -93,7 +94,7 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter { @@ -93,7 +94,7 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter {
converter.setApplicationContext(context);
}
/*
/*
* (non-Javadoc)
* @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter#addArgumentResolvers(java.util.List)
*/
@ -111,7 +112,7 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter { @@ -111,7 +112,7 @@ public class SpringDataWebConfiguration extends WebMvcConfigurerAdapter {
argumentResolvers.add(resolver);
}
/*
/*
* (non-Javadoc)
* @see org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter#extendMessageConverters(java.util.List)
*/

76
src/test/java/org/springframework/data/web/config/SpringDataWebConfigurationIntegrationTests.java

@ -22,8 +22,8 @@ import static org.springframework.test.util.ReflectionTestUtils.*; @@ -22,8 +22,8 @@ import static org.springframework.test.util.ReflectionTestUtils.*;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
import org.hamcrest.Matcher;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectFactory;
@ -31,61 +31,18 @@ import org.springframework.context.support.GenericApplicationContext; @@ -31,61 +31,18 @@ import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.web.ProjectingJackson2HttpMessageConverter;
import org.springframework.data.web.XmlBeamHttpMessageConverter;
import org.springframework.data.web.querydsl.QuerydslPredicateArgumentResolver;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.instrument.classloading.ShadowingClassLoader;
import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
/**
* Integration test for {@link SpringDataWebConfiguration}.
*
* @author Christoph Strobl
* @author Jens Schauder
*/
public class SpringDataWebConfigurationIntegrationTests {
@Test // DATACMNS-669
public void shouldNotAddQuerydslPredicateArgumentResolverWhenQuerydslNotPresent() throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
ClassLoader classLoader = initClassLoader("com.mysema");
Object config = classLoader.loadClass(SpringDataWebConfiguration.class.getName())
.newInstance();
setField(config, "context", classLoader.loadClass(GenericWebApplicationContext.class.getName()).newInstance()
);
setField(config, "conversionService", classLoader.loadClass(ObjectFactoryImpl.class.getName()).newInstance());
List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver>();
invokeMethod(config, "addArgumentResolvers", argumentResolvers);
assertThat(argumentResolvers,
not(hasItem((Matcher) instanceWithClassName(QuerydslPredicateArgumentResolver.class))));
}
@Test // DATACMNS-669
@Ignore("currently fails because he setup is not sufficient to trigger loading of the QuerydslArgumentResolver. See DATACMNS-993")
public void shouldAddQuerydslPredicateArgumentResolverWhenQuerydslPresent() throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
ClassLoader classLoader = initClassLoader("load.everything");
Object config = classLoader.loadClass(SpringDataWebConfiguration.class.getName())
.newInstance();
setField(config, "context", classLoader.loadClass(GenericWebApplicationContext.class.getName()).newInstance());
setField(config, "conversionService", classLoader.loadClass(ObjectFactoryImpl.class.getName()).newInstance());
List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver>();
invokeMethod(config, "addArgumentResolvers", argumentResolvers);
assertThat(argumentResolvers,
hasItem((Matcher) instanceWithClassName(QuerydslPredicateArgumentResolver.class)));
}
@Test // DATACOMNS-987
@Test // DATACMNS-987
public void shouldNotLoadJacksonConverterWhenJacksonNotPresent() {
SpringDataWebConfiguration config = createConfigWithClassLoaderExcluding("com.fasterxml.jackson");
@ -98,7 +55,7 @@ public class SpringDataWebConfigurationIntegrationTests { @@ -98,7 +55,7 @@ public class SpringDataWebConfigurationIntegrationTests {
instanceWithClassName(ProjectingJackson2HttpMessageConverter.class))));
}
@Test // DATACOMNS-987
@Test // DATACMNS-987
public void shouldNotLoadJacksonConverterWhenJaywayNotPresent() {
SpringDataWebConfiguration config = createConfigWithClassLoaderExcluding("com.jayway");
@ -111,8 +68,8 @@ public class SpringDataWebConfigurationIntegrationTests { @@ -111,8 +68,8 @@ public class SpringDataWebConfigurationIntegrationTests {
instanceWithClassName(ProjectingJackson2HttpMessageConverter.class))));
}
@Test // DATACOMNS-987
public void shouldNotLoadXBeamConverterWhenXBeamNotPresent() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
@Test // DATACMNS-987
public void shouldNotLoadXBeamConverterWhenXBeamNotPresent() throws Exception {
SpringDataWebConfiguration config = createConfigWithClassLoaderExcluding("org.xmlbeam");
@ -124,10 +81,8 @@ public class SpringDataWebConfigurationIntegrationTests { @@ -124,10 +81,8 @@ public class SpringDataWebConfigurationIntegrationTests {
instanceWithClassName(XmlBeamHttpMessageConverter.class))));
}
@Test // DATACOMNS-987
public void shouldLoadAllConvertersWhenDependenciesArePresent() throws ClassNotFoundException,
IllegalAccessException, InstantiationException {
@Test // DATACMNS-987
public void shouldLoadAllConvertersWhenDependenciesArePresent() throws Exception {
SpringDataWebConfiguration config = createConfigWithClassLoaderExcluding("load.everything");
@ -135,12 +90,14 @@ public class SpringDataWebConfigurationIntegrationTests { @@ -135,12 +90,14 @@ public class SpringDataWebConfigurationIntegrationTests {
config.extendMessageConverters(converters);
assertThat(converters, containsInAnyOrder( //
instanceWithClassName(XmlBeamHttpMessageConverter.class), //
instanceWithClassName(ProjectingJackson2HttpMessageConverter.class)));
assertThat(converters,
containsInAnyOrder( //
instanceWithClassName(XmlBeamHttpMessageConverter.class), //
instanceWithClassName(ProjectingJackson2HttpMessageConverter.class)));
}
private SpringDataWebConfiguration createConfigWithClassLoaderExcluding(String excludedClassNamePrefix) {
ClassLoader classLoader = initClassLoader(excludedClassNamePrefix);
SpringDataWebConfiguration config = new SpringDataWebConfiguration();
@ -153,9 +110,8 @@ public class SpringDataWebConfigurationIntegrationTests { @@ -153,9 +110,8 @@ public class SpringDataWebConfigurationIntegrationTests {
}
/**
* creates a Matcher that check if an object is an instance of a class with the same name as the provided class.
* This is necessary since we are dealing with multiple classloaders which would make a simple instanceof fail all
* the time
* creates a Matcher that check if an object is an instance of a class with the same name as the provided class. This
* is necessary since we are dealing with multiple classloaders which would make a simple instanceof fail all the time
*
* @param expectedClass the class that is expected (possibly loaded by a different classloader).
* @return a Matcher

Loading…
Cancel
Save