Skip to content

Commit

Permalink
Merge pull request #13 from zhurpavel/issue_12_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xxlabaza authored Nov 8, 2016
2 parents 4c9bfdd + 0edfa65 commit 269cfbc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion feign-form/src/main/java/feign/form/FormEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public FormEncoder(Encoder delegate) {

@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
if (bodyType != MAP_STRING_WILDCARD) {
if (!MAP_STRING_WILDCARD.equals(bodyType)) {
deligate.encode(object, bodyType, template);
return;
}
Expand Down
11 changes: 11 additions & 0 deletions feign-form/src/test/java/feign/form/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.springframework.http.HttpStatus.I_AM_A_TEAPOT;
import static org.springframework.http.HttpStatus.LOCKED;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.MediaType.APPLICATION_FORM_URLENCODED_VALUE;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

Expand Down Expand Up @@ -95,4 +96,14 @@ public ResponseEntity<Integer> queryMap(@RequestParam("filter") List<String> fil
}
return ResponseEntity.status(status).body(filters.size());
}

@RequestMapping(
value = "/wild-card-map",
method = POST,
consumes = APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<Integer> wildCardMap(
@RequestParam("key1") String key1, @RequestParam("key2") String key2) {
HttpStatus status = key1.equals(key2) ? OK : BAD_REQUEST;
return ResponseEntity.status(status).body(null);
}
}
64 changes: 64 additions & 0 deletions feign-form/src/test/java/feign/form/WildCardMapTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package feign.form;

import static feign.Logger.Level.FULL;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;

import feign.*;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = DEFINED_PORT, classes = Server.class)
public class WildCardMapTest {

private static FormUrlEncodedApi API;

@BeforeClass
public static void configureClient() {
API =
Feign.builder()
.encoder(new FormEncoder())
.logger(new Logger.JavaLogger().appendToFile("log.txt"))
.logLevel(FULL)
.target(FormUrlEncodedApi.class, "http://localhost:8080");
}

@Test
public void testOk() {
Map<String, Object> param =
new HashMap<String, Object>() {
{
put("key1", "1");
put("key2", "1");
}
};
Response response = API.wildCardMap(param);
Assert.assertEquals(200, response.status());
}

@Test
public void testBadRequest() {
Map<String, Object> param =
new HashMap<String, Object>() {
{
put("key1", "1");
put("key2", "2");
}
};
Response response = API.wildCardMap(param);
Assert.assertEquals(400, response.status());
}

interface FormUrlEncodedApi {

@RequestLine("POST /wild-card-map")
@Headers("Content-Type: application/x-www-form-urlencoded")
Response wildCardMap(Map<String, ?> param);
}
}

0 comments on commit 269cfbc

Please sign in to comment.