This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mkwaczynski
committed
Dec 1, 2015
1 parent
78fb08b
commit 5967751
Showing
8 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Repro project for SPR-13733 | ||
|
||
Please, run org.springframework.issues.spr13733.WitcherResourceTest to reproduce the issue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<groupId>org.springframework.boot</groupId> | ||
<version>1.3.0.RELEASE</version> | ||
<relativePath/> | ||
</parent> | ||
|
||
<groupId>org.springframework.issues</groupId> | ||
<artifactId>SPR-13733</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>Spring MVC Issue Reproduction Project</name> | ||
<packaging>war</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>${java.version}</maven.compiler.source> | ||
<maven.compiler.target>${java.version}</maven.compiler.target> | ||
<java.version>1.8</java.version> | ||
|
||
</properties> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-tomcat</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context-support</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-loader-tools</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-aop</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-logging</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>3.2.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<repositories> | ||
<repository> | ||
<id>spring-maven-snapshot</id> | ||
<name>Springframework Maven Snapshot Repository</name> | ||
<url>http://repo.spring.io/snapshot</url> | ||
<snapshots> | ||
<enabled>true</enabled> | ||
</snapshots> | ||
</repository> | ||
</repositories> | ||
|
||
</project> | ||
|
20 changes: 20 additions & 0 deletions
20
SPR-13733/src/main/java/org/springframework/issues/spr13733/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.springframework.issues.spr13733; | ||
|
||
import java.net.UnknownHostException; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ComponentScan | ||
@EnableAutoConfiguration | ||
public class Application { | ||
|
||
public static void main(final String[] args) throws UnknownHostException { | ||
final SpringApplication app = new SpringApplication(Application.class); | ||
app.run(args); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
...org/springframework/issues/spr13733/config/MockClientHttpRequestFactoryConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.springframework.issues.spr13733.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.client.ClientHttpRequestFactory; | ||
import org.springframework.test.web.client.MockMvcClientHttpRequestFactory; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
@Configuration | ||
public class MockClientHttpRequestFactoryConfiguration { | ||
|
||
@Autowired | ||
protected WebApplicationContext wac; | ||
|
||
@Bean | ||
public ClientHttpRequestFactory clientHttpRequestFactory() { | ||
final MockMvc mockMvc = MockMvcBuilders | ||
.webAppContextSetup(this.wac) | ||
.build(); | ||
return new MockMvcClientHttpRequestFactory(mockMvc); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...733/src/main/java/org/springframework/issues/spr13733/config/RestClientConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.springframework.issues.spr13733.config; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.client.ClientHttpRequestFactory; | ||
import org.springframework.web.client.RestOperations; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
@Configuration | ||
public class RestClientConfiguration { | ||
|
||
@Autowired | ||
private ClientHttpRequestFactory clientHttpRequestFactory; | ||
|
||
@Bean | ||
public RestOperations restOperations() { | ||
final RestTemplate restTemplate = new RestTemplate(); | ||
restTemplate.setRequestFactory(clientHttpRequestFactory); | ||
return restTemplate; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
SPR-13733/src/main/java/org/springframework/issues/spr13733/web/WitcherResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.springframework.issues.spr13733.web; | ||
|
||
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; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/witcher/contract") | ||
public class WitcherResource { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(WitcherResource.class); | ||
|
||
@RequestMapping(value = "validate", method = POST, consumes = APPLICATION_FORM_URLENCODED_VALUE, produces = APPLICATION_JSON_VALUE) | ||
public WitcherResponse validateContract(@RequestBody final MultiValueMap<String, String> data) { | ||
log.info("Witcher contract: {}", data); | ||
|
||
final WitcherResponse witcherResponse = new WitcherResponse(); | ||
witcherResponse.setAccepted(true); | ||
return witcherResponse; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
SPR-13733/src/main/java/org/springframework/issues/spr13733/web/WitcherResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.springframework.issues.spr13733.web; | ||
|
||
public final class WitcherResponse { | ||
|
||
private boolean accepted; | ||
|
||
public boolean isAccepted() { | ||
return accepted; | ||
} | ||
|
||
public void setAccepted(final boolean accepted) { | ||
this.accepted = accepted; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
SPR-13733/src/test/java/org/springframework/issues/spr13733/WitcherResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.springframework.issues.spr13733; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.IntegrationTest; | ||
import org.springframework.boot.test.SpringApplicationConfiguration; | ||
import org.springframework.issues.spr13733.web.WitcherResponse; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.context.web.WebAppConfiguration; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.client.RestOperations; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringApplicationConfiguration(classes = Application.class) | ||
@WebAppConfiguration | ||
@IntegrationTest | ||
public class WitcherResourceTest { | ||
|
||
private static final boolean SEND_WITH_PARAMS_IN_URL = true; | ||
|
||
private static final boolean SEND_WITH_PARAMS_IN_BODY = false; | ||
|
||
@Autowired | ||
private RestOperations restOperations; | ||
|
||
private void shouldAcceptContract(final boolean sendWithParamsInUrl) { | ||
// given | ||
String url = "/witcher/contract/validate"; | ||
|
||
final String contract = "The Apiarian Phantom"; | ||
final String beast = "Wild Hunt Hound"; | ||
final String reward = "120 crowns"; | ||
|
||
final MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>(); | ||
|
||
if (sendWithParamsInUrl) { | ||
url += "?contract=" + contract + "&beast=" + beast + "&reward=" + reward; | ||
} else { | ||
parameters.add("contract", contract); | ||
parameters.add("beast", beast); | ||
parameters.add("reward", reward); | ||
} | ||
|
||
// when | ||
final WitcherResponse witcherResponse = restOperations | ||
.postForObject(url, parameters, WitcherResponse.class); | ||
|
||
// then | ||
assertThat(witcherResponse.isAccepted()).isTrue(); | ||
} | ||
|
||
@Test | ||
public void shouldAcceptContractWhenPostRequestSentWithParamsInUrl() throws Exception { | ||
shouldAcceptContract(SEND_WITH_PARAMS_IN_URL); | ||
} | ||
|
||
@Test | ||
public void shouldAcceptContractWhenPostRequestWithParamsInBody() throws Exception { | ||
shouldAcceptContract(SEND_WITH_PARAMS_IN_BODY); | ||
} | ||
|
||
} |