@ -18,6 +18,8 @@ package org.springframework.cloud.netflix.feign.support;
@@ -18,6 +18,8 @@ package org.springframework.cloud.netflix.feign.support;
import java.lang.reflect.InvocationTargetException ;
import java.lang.reflect.Method ;
import java.text.CollationElementIterator ;
import java.util.Collection ;
import java.util.List ;
import java.util.Map ;
@ -25,6 +27,7 @@ import org.junit.Before;
@@ -25,6 +27,7 @@ import org.junit.Before;
import org.junit.Test ;
import org.springframework.http.MediaType ;
import org.springframework.http.ResponseEntity ;
import org.springframework.util.MultiValueMap ;
import org.springframework.util.ReflectionUtils ;
import org.springframework.web.bind.annotation.ExceptionHandler ;
import org.springframework.web.bind.annotation.PathVariable ;
@ -340,6 +343,48 @@ public class SpringMvcContractTests {
@@ -340,6 +343,48 @@ public class SpringMvcContractTests {
return false ;
}
@Test
public void testProcessHeaderMap ( ) throws Exception {
Method method = TestTemplate_HeaderMap . class . getDeclaredMethod ( "headerMap" ,
MultiValueMap . class , String . class ) ;
MethodMetadata data = this . contract
. parseAndValidateMetadata ( method . getDeclaringClass ( ) , method ) ;
assertEquals ( "/headerMap" , data . template ( ) . url ( ) ) ;
assertEquals ( "GET" , data . template ( ) . method ( ) ) ;
assertEquals ( 0 , data . headerMapIndex ( ) . intValue ( ) ) ;
Map < String , Collection < String > > headers = data . template ( ) . headers ( ) ;
assertEquals ( "{aHeader}" , headers . get ( "aHeader" ) . iterator ( ) . next ( ) ) ;
}
@Test ( expected = IllegalStateException . class )
public void testProcessHeaderMapMoreThanOnce ( ) throws Exception {
Method method = TestTemplate_HeaderMap . class . getDeclaredMethod (
"headerMapMoreThanOnce" , MultiValueMap . class , MultiValueMap . class ) ;
this . contract . parseAndValidateMetadata ( method . getDeclaringClass ( ) , method ) ;
}
@Test
public void testProcessQueryMap ( ) throws Exception {
Method method = TestTemplate_QueryMap . class . getDeclaredMethod ( "queryMap" ,
MultiValueMap . class , String . class ) ;
MethodMetadata data = this . contract
. parseAndValidateMetadata ( method . getDeclaringClass ( ) , method ) ;
assertEquals ( "/queryMap" , data . template ( ) . url ( ) ) ;
assertEquals ( "GET" , data . template ( ) . method ( ) ) ;
assertEquals ( 0 , data . queryMapIndex ( ) . intValue ( ) ) ;
Map < String , Collection < String > > params = data . template ( ) . queries ( ) ;
assertEquals ( "{aParam}" , params . get ( "aParam" ) . iterator ( ) . next ( ) ) ;
}
@Test ( expected = IllegalStateException . class )
public void testProcessQueryMapMoreThanOnce ( ) throws Exception {
Method method = TestTemplate_QueryMap . class . getDeclaredMethod (
"queryMapMoreThanOnce" , MultiValueMap . class , MultiValueMap . class ) ;
this . contract . parseAndValidateMetadata ( method . getDeclaringClass ( ) , method ) ;
}
public interface TestTemplate_Simple {
@RequestMapping ( value = "/test/{id}" , method = RequestMethod . GET , produces = MediaType . APPLICATION_JSON_VALUE )
ResponseEntity < TestObject > getTest ( @PathVariable ( "id" ) String id ) ;
@ -380,6 +425,30 @@ public class SpringMvcContractTests {
@@ -380,6 +425,30 @@ public class SpringMvcContractTests {
ResponseEntity < TestObject > getTest ( @RequestParam Map < String , String > params ) ;
}
public interface TestTemplate_HeaderMap {
@RequestMapping ( path = "/headerMap" )
String headerMap (
@RequestHeader MultiValueMap < String , String > headerMap ,
@RequestHeader ( name = "aHeader" ) String aHeader ) ;
@RequestMapping ( path = "/headerMapMoreThanOnce" )
String headerMapMoreThanOnce (
@RequestHeader MultiValueMap < String , String > headerMap1 ,
@RequestHeader MultiValueMap < String , String > headerMap2 ) ;
}
public interface TestTemplate_QueryMap {
@RequestMapping ( path = "/queryMap" )
String queryMap (
@RequestParam MultiValueMap < String , String > queryMap ,
@RequestParam ( name = "aParam" ) String aParam ) ;
@RequestMapping ( path = "/queryMapMoreThanOnce" )
String queryMapMoreThanOnce (
@RequestParam MultiValueMap < String , String > queryMap1 ,
@RequestParam MultiValueMap < String , String > queryMap2 ) ;
}
@JsonAutoDetect
@RequestMapping ( "/advanced" )
public interface TestTemplate_Advanced {