Add support for feign's QueryMap annotation for Object mapping (#79)

* Add QueryMapParameterProcessor

* Add license to QueryMapParameterProcessor

* Use SpringQueryMap instead of QueryMap. Add test.

* Add documentation and license to SpringQueryMap

* SpringQueryMap docs

* Fix typos
This commit is contained in:
Momo
2018-12-06 15:26:36 -05:00
committed by Ryan Baxter
parent cc2fe823c3
commit d46fb3a92e
5 changed files with 164 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2018 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.
@@ -31,6 +31,7 @@ import feign.Param;
import org.junit.Before;
import org.junit.Test;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.NumberFormat;
@@ -61,6 +62,7 @@ import feign.MethodMetadata;
/**
* @author chadjaros
* @author Halvdan Hoem Grelland
* @author Aram Peres
*/
public class SpringMvcContractTests {
private static final Class<?> EXECUTABLE_TYPE;
@@ -488,6 +490,20 @@ public class SpringMvcContractTests {
assertEquals("{aParam}", params.get("aParam").iterator().next());
}
@Test
public void testProcessQueryMapObject() throws Exception {
Method method = TestTemplate_QueryMap.class.getDeclaredMethod("queryMapObject",
TestObject.class, String.class);
MethodMetadata data = this.contract
.parseAndValidateMetadata(method.getDeclaringClass(), method);
assertEquals("/queryMapObject", 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(
@@ -573,6 +589,11 @@ public class SpringMvcContractTests {
String queryMapMoreThanOnce(
@RequestParam MultiValueMap<String, String> queryMap1,
@RequestParam MultiValueMap<String, String> queryMap2);
@RequestMapping(path = "/queryMapObject")
String queryMapObject(
@SpringQueryMap TestObject queryMap,
@RequestParam(name = "aParam") String aParam);
}
@JsonAutoDetect