#304 - Added build profiles for Spring 4.x versions.

Also added config file for Travis CI build. Adapted test cases to mitigate API changes.
This commit is contained in:
Oliver Gierke
2015-02-26 14:52:58 +01:00
parent bf9584f91e
commit 1953e6400b
4 changed files with 108 additions and 9 deletions

17
.travis.yml Normal file
View File

@@ -0,0 +1,17 @@
language: java
jdk:
- oraclejdk8
env:
matrix:
- PROFILE=non-existant
- PROFILE=spring40
# - PROFILE=spring40-next
- PROFILE=spring41
- PROFILE=spring41-next
- PROFILE=spring42-next
cache:
directories:
- $HOME/.m2
sudo: false
install: true
script: "mvn clean dependency:list test -P${PROFILE} -Dsort"

60
pom.xml
View File

@@ -13,7 +13,7 @@
hyper-text driven REST web services.
</description>
<inceptionYear>2012-2014</inceptionYear>
<inceptionYear>2012-2015</inceptionYear>
<organization>
<name>Pivotal, Inc.</name>
@@ -24,7 +24,7 @@
<developer>
<id>ogierke</id>
<name>Oliver Gierke</name>
<email>ogierke(at)gopivotal.com</email>
<email>ogierke(at)pivotal.io</email>
<organization>Pivotal, Inc.</organization>
<roles>
<role>Project lead</role>
@@ -70,6 +70,62 @@
<bundlor.failOnWarnings>true</bundlor.failOnWarnings>
</properties>
<profiles>
<profile>
<id>spring40</id>
<properties>
<spring.version>4.0.9.RELEASE</spring.version>
</properties>
</profile>
<profile>
<id>spring40-next</id>
<properties>
<spring.version>4.0.10.BUILD-SNAPSHOT</spring.version>
</properties>
<repositories>
<repository>
<id>spring-libs-snapshot</id>
<url>http://repo.spring.io/libs-snapshot</url>
</repository>
</repositories>
</profile>
<profile>
<id>spring41</id>
<properties>
<spring.version>4.1.5.RELEASE</spring.version>
</properties>
</profile>
<profile>
<id>spring41-next</id>
<properties>
<spring.version>4.1.6.BUILD-SNAPSHOT</spring.version>
</properties>
<repositories>
<repository>
<id>spring-libs-snapshot</id>
<url>http://repo.spring.io/libs-snapshot</url>
</repository>
</repositories>
</profile>
<profile>
<id>spring42-next</id>
<properties>
<spring.version>4.2.0.BUILD-SNAPSHOT</spring.version>
</properties>
<repositories>
<repository>
<id>spring-libs-snapshot</id>
<url>http://repo.spring.io/libs-snapshot</url>
</repository>
</repositories>
</profile>
</profiles>
<dependencies>
<dependency>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-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.
@@ -18,6 +18,7 @@ package org.springframework.hateoas.config;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -45,8 +46,10 @@ import org.springframework.hateoas.mvc.TypeConstrainedMappingJackson2HttpMessage
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodArgumentResolverComposite;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
@@ -101,7 +104,7 @@ public class EnableHypermediaSupportIntegrationTest {
boolean found = false;
for (HandlerMethodArgumentResolver resolver : adapter.getArgumentResolvers().getResolvers()) {
for (HandlerMethodArgumentResolver resolver : getResolvers(adapter)) {
if (resolver instanceof AbstractMessageConverterMethodArgumentResolver) {
@@ -161,6 +164,29 @@ public class EnableHypermediaSupportIntegrationTest {
Matchers.<HttpMessageConverter<?>> hasItems(instanceOf(MappingJackson2HttpMessageConverter.class)));
}
/**
* Method to mitigate API changes between Spring 3.2 and 4.0.
*
* @param adapter
* @return
*/
@SuppressWarnings("unchecked")
private static List<HandlerMethodArgumentResolver> getResolvers(RequestMappingHandlerAdapter adapter) {
Method method = ReflectionUtils.findMethod(RequestMappingHandlerAdapter.class, "getArgumentResolvers");
Object result = ReflectionUtils.invokeMethod(method, adapter);
if (result instanceof List) {
return (List<HandlerMethodArgumentResolver>) result;
}
if (result instanceof HandlerMethodArgumentResolverComposite) {
return ((HandlerMethodArgumentResolverComposite) result).getResolvers();
}
throw new IllegalStateException("Unexpected result when looking up argument resolvers!");
}
@Configuration
@Import(DelegateConfig.class)
static class HalConfig {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-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.
@@ -23,7 +23,7 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.hateoas.core.ControllerEntityLinksUnitTest.Person;
import org.springframework.hateoas.core.ControllerEntityLinksUnitTest.SampleController;
@@ -37,8 +37,7 @@ import org.springframework.stereotype.Controller;
*/
public class ControllerEntityLinksFactoryBeanUnitTest {
@Rule
public ExpectedException exception = ExpectedException.none();
@Rule public ExpectedException exception = ExpectedException.none();
@Test
public void rejectsFactoryBeanIfAnnotationNotSet() throws Exception {
@@ -56,7 +55,8 @@ public class ControllerEntityLinksFactoryBeanUnitTest {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("controller", new RootBeanDefinition(SampleController.class));
ApplicationContext context = new GenericApplicationContext(factory);
ConfigurableApplicationContext context = new GenericApplicationContext(factory);
context.refresh();
ControllerEntityLinksFactoryBean builder = new ControllerEntityLinksFactoryBean();
builder.setAnnotation(Controller.class);