Updated docs with a fast intro

This commit is contained in:
Marcin Grzejszczak
2016-07-15 14:27:03 +02:00
parent bc22227fe3
commit a8a1bc1f2e
16 changed files with 253 additions and 106 deletions

View File

@@ -43,10 +43,12 @@ public class LoanApplicationService {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1);
// tag::client_call_server[]
ResponseEntity<FraudServiceResponse> response =
restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT,
new HttpEntity<>(request, httpHeaders),
FraudServiceResponse.class);
// end::client_call_server[]
return response.getBody();
}

View File

@@ -30,6 +30,7 @@ class LoanApplicationServiceSpec extends Specification {
loanApplication.rejectionReason == null
}
// tag::client_tdd[]
def 'should be rejected due to abnormal loan amount'() {
given:
LoanApplication application =
@@ -40,5 +41,6 @@ class LoanApplicationServiceSpec extends Specification {
loanApplication.loanApplicationStatus == LoanApplicationStatus.LOAN_APPLICATION_REJECTED
loanApplication.rejectionReason == 'Amount too high'
}
// end::client_tdd[]
}

View File

@@ -20,16 +20,22 @@ public class FraudDetectionController {
private static final String AMOUNT_TOO_HIGH = "Amount too high";
private static final BigDecimal MAX_AMOUNT = new BigDecimal("5000");
// tag::server_api[]
@RequestMapping(
value = "/fraudcheck",
method = PUT,
consumes = FRAUD_SERVICE_JSON_VERSION_1,
produces = FRAUD_SERVICE_JSON_VERSION_1)
public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) {
// end::server_api[]
// tag::new_impl[]
if (amountGreaterThanThreshold(fraudCheck)) {
return new FraudCheckResult(FraudCheckStatus.FRAUD, AMOUNT_TOO_HIGH);
}
// end::new_impl[]
// tag::initial_impl[]
return new FraudCheckResult(FraudCheckStatus.OK, NO_REASON);
// end::initial_impl[]
}
private boolean amountGreaterThanThreshold(FraudCheck fraudCheck) {

View File

@@ -2,8 +2,8 @@ package contracts
org.springframework.cloud.contract.spec.Contract.make {
request {
method """PUT"""
url """/fraudcheck"""
method 'PUT'
url '/fraudcheck'
body("""
{
"clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}",
@@ -11,7 +11,7 @@ org.springframework.cloud.contract.spec.Contract.make {
"""
)
headers {
header("""Content-Type""", """application/vnd.fraud.v1+json""")
header('Content-Type', 'application/vnd.fraud.v1+json')
}
}