Skip to content

Commit

Permalink
Merge pull request #54 from otrosien/feature/contentTypeMatching
Browse files Browse the repository at this point in the history
GH-50 - ContentType is stripped when using custom vendor and version format
  • Loading branch information
jensfischer1515 authored Oct 18, 2017
2 parents 8e7f783 + f32611a commit fd6730a
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cache:
directories:
- "$HOME/.gradle"
install: true
script: "./gradlew clean build jacoco coveralls"
script: "./gradlew clean build jacocoTestReport coveralls"
after_success:
- if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then ./publish.sh; fi
env:
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,20 @@ dependencies {
}
```

Spring Boot 1.3.x users: Please make sure you use the current release of Spring REST Docs, which is
`1.1.2.RELEASE` as of this writing. The `1.0.x.RELEASE`, included with Spring Boot 1.3 is not compatible with this plugin.
Spring Boot 1.3.x users: Please make sure you use Spring REST Docs `1.1.+` or newer. The `1.0.x.RELEASE`, included with Spring Boot 1.3 is not compatible with this plugin.
The example below shows how to set Spring REST Docs to this version, when using Spring dependency management.

```groovy
dependencyManagement.imports {
ext['spring-restdocs.version'] = '1.1.2.RELEASE'
ext['spring-restdocs.version'] = '1.2.2.RELEASE'
}
```

When using maven:

```xml
<properties>
<spring-restdocs.version>1.1.2.RELEASE</spring-restdocs.version>
<spring-restdocs.version>1.2.2.RELEASE</spring-restdocs.version>
</properties>
<dependency>
<groupId>com.epages</groupId>
Expand Down Expand Up @@ -181,7 +180,7 @@ transitive versions coming in through maven dependencies, you need to add an exp
project, like shown in the following gradle example:

```groovy
testCompile('com.github.tomakehurst:wiremock:2.3.1')
testCompile('com.github.tomakehurst:wiremock:2.8.0')
```

### Configuring your test to use the WireMock stubs
Expand Down
2 changes: 1 addition & 1 deletion client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE'
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.7.RELEASE'
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Sep 01 11:42:06 CEST 2016
#Wed Oct 04 08:49:08 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-bin.zip
2 changes: 1 addition & 1 deletion server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE'
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.7.RELEASE'
}
}

Expand Down
4 changes: 2 additions & 2 deletions wiremock-spring-boot-starter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE'
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.7.RELEASE'
}
}

Expand All @@ -30,7 +30,7 @@ dependencies {
compile 'org.springframework.boot:spring-boot-starter-test'
compile 'org.springframework.boot:spring-boot-starter'
compileOnly 'org.springframework.boot:spring-boot-configuration-processor'
compile 'com.github.tomakehurst:wiremock-standalone:2.5.1'
compile 'com.github.tomakehurst:wiremock-standalone:2.8.0'
testCompile 'org.springframework:spring-web'
}

Expand Down
6 changes: 3 additions & 3 deletions wiremock/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ repositories {
}

dependencies {
compile "org.springframework.restdocs:spring-restdocs-core:1.1.2.RELEASE"
compile "org.springframework.restdocs:spring-restdocs-core:1.2.2.RELEASE"
compileOnly 'junit:junit:4.12'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.7.6'
testCompile 'org.mockito:mockito-core:2.10.0'
testCompile 'uk.co.datumedge:hamcrest-json:0.2'
testCompile 'com.google.guava:guava:21.0'
testCompile 'com.google.guava:guava:23.0'
}

group = 'com.epages'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,15 @@ private Map<Object, Object> requestHeaders(OperationRequest request) {
List<String> values = e.getValue();
if (!values.isEmpty()) {
String mediaType = values.get(0);
// TODO : use proper MediaType parsing, e.g. from guava.
// TODO : use proper MediaType parsing
if(mediaType.contains("+")) {
mediaType = mediaType.replaceAll(".*[+]","");
} else {
mediaType = mediaType.replaceAll(".*/","");
}
if(mediaType.contains(";")) {
mediaType = mediaType.replaceAll(";.*","");
}
requestHeaders.put(e.getKey(), Maps.of("contains", mediaType));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,39 +93,50 @@ public void simpleRequest() throws IOException {
@Test
public void getRequestWithParams() throws IOException {
this.expectedSnippet.expectWireMockJson("get-request").withContents(
(Matcher<String>) SameJSONAs.sameJSONAs(new ObjectMapper().writeValueAsString(expectedJsonForGetRequestWithParams())));
(Matcher<String>) SameJSONAs.sameJSONAs(new ObjectMapper().writeValueAsString(
of( //
"request", //
of("method", "GET", "urlPath", "/foo", "queryParameters", //
of("a", of("equalTo", "b")), "headers", of("Accept", of("contains", "json"))), //
"response", //
of("headers", emptyMap(), "body", "", "status", 200))
)));
wiremockJson().document(operationBuilder("get-request").request("http://localhost/foo?a=b&c=").method("GET")
.header("Accept", "application/json").build());
}

private ImmutableMap<String, ImmutableMap<String, ? extends Object>> expectedJsonForGetRequestWithParams() {
return of( //
"request", //
of("method", "GET", "urlPath", "/foo", "queryParameters", //
of("a", of("equalTo", "b")), "headers", of("Accept", of("contains", "json"))), //
"response", //
of("headers", emptyMap(), "body", "", "status", 200));
}

@SuppressWarnings("unchecked")
@Test
public void postRequest() throws IOException {
this.expectedSnippet.expectWireMockJson("post-request").withContents((Matcher<String>) SameJSONAs
.sameJSONAs(new ObjectMapper().writeValueAsString(expectedJsonForPostRequest())));
.sameJSONAs(new ObjectMapper().writeValueAsString(
of( //
"request", //
of("method", "POST", "urlPath", "/", "headers", of("Content-Type", of("contains", "uri-list"))), //
"response", //
of("headers", //
of("Content-Length", "16", "Content-Type", "text/plain"),
"body", "response-content", "status", 200)))));
OperationBuilder operationBuilder = operationBuilder("post-request");
operationBuilder.response().content("response-content").header("Content-Type", "text/plain").build();
wiremockJson().document(operationBuilder.request("http://localhost/").method("POST")
.header("Content-Type", "text/uri-list").content("http://some.uri").build());
}

private Map<String, ? extends Object> expectedJsonForPostRequest() {
return of( //
"request", //
of("method", "POST", "urlPath", "/", "headers", of("Content-Type", of("contains", "uri-list"))), //
"response", //
of("headers",
of("Content-Length", "16", "Content-Type", "text/plain"),
"body", "response-content", "status", 200));
@Test
@SuppressWarnings("unchecked")
public void customMediaType() throws IOException {
this.expectedSnippet.expectWireMockJson("custom-mediatype").withContents((Matcher<String>) SameJSONAs
.sameJSONAs(new ObjectMapper().writeValueAsString(
of( //
"request", //
of("method", "GET", "urlPath", "/foo",
"headers", of("Accept", of("contains", "json"))), //
"response", //
of("headers", emptyMap(), "body", "", "status", 200))
)));
wiremockJson().document(operationBuilder("custom-mediatype").request("http://localhost/foo").method("GET")
.header("Accept", "application/com.carlosjgp.myservice+json; version=1.0").build());
}

public OperationBuilder operationBuilder(String name) {
Expand Down

0 comments on commit fd6730a

Please sign in to comment.