Merge branch '1.2.x'

This commit is contained in:
Marcin Grzejszczak
2018-04-11 12:48:22 +02:00
39 changed files with 1041 additions and 10 deletions

View File

@@ -86,6 +86,17 @@ public class LoanApplicationService {
return response.getBody().getCount();
}
public String getCookies() {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Cookie", "name=foo");
httpHeaders.add("Cookie", "name2=bar");
ResponseEntity<String> response =
restTemplate.exchange("http://localhost:" + port + "/frauds/name", HttpMethod.GET,
new HttpEntity<>(httpHeaders),
String.class);
return response.getBody();
}
public void setPort(int port) {
this.port = port;
}

View File

@@ -73,4 +73,12 @@ public class LoanApplicationServiceTests {
assertThat(count).isEqualTo(100);
}
@Test
public void shouldSuccessfullyGetCookies() {
// when:
String cookies = service.getCookies();
// then:
assertThat(cookies).isEqualTo("foo bar");
}
}

View File

@@ -1,5 +1,7 @@
package com.example.fraud;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@@ -24,6 +26,12 @@ class FraudNameController {
}
return new NameResponse("Don't worry " + request.getName() + " you're not a fraud");
}
@GetMapping(value = "/frauds/name")
public String checkByName(@CookieValue("name") String value,
@CookieValue("name2") String value2) {
return value + " " + value2;
}
}
interface FraudVerifier {

View File

@@ -0,0 +1,16 @@
package contracts.fraudname
org.springframework.cloud.contract.spec.Contract.make {
request {
method GET()
url '/frauds/name'
cookies {
cookie("name", "foo")
cookie(name2: "bar")
}
}
response {
status 200
body("foo bar")
}
}