Checkstyle and jdk11 fix with spock
This commit is contained in:
@@ -14,11 +14,12 @@ public class Application {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@RestController
|
||||
class CustomController {
|
||||
|
||||
@GetMapping("/foo")
|
||||
String foo() {
|
||||
return "bar";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,8 +17,7 @@ import com.example.loan.model.LoanApplicationStatus;
|
||||
@Service
|
||||
public class LoanApplicationService {
|
||||
|
||||
private static final String FRAUD_SERVICE_JSON_VERSION_1 =
|
||||
"application/vnd.fraud.v1+json";
|
||||
private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json";
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
@@ -29,11 +28,9 @@ public class LoanApplicationService {
|
||||
}
|
||||
|
||||
public LoanApplicationResult loanApplication(LoanApplication loanApplication) {
|
||||
FraudServiceRequest request =
|
||||
new FraudServiceRequest(loanApplication);
|
||||
FraudServiceRequest request = new FraudServiceRequest(loanApplication);
|
||||
|
||||
FraudServiceResponse response =
|
||||
sendRequestToFraudDetectionService(request);
|
||||
FraudServiceResponse response = sendRequestToFraudDetectionService(request);
|
||||
|
||||
return buildResponseFromFraudResult(response);
|
||||
}
|
||||
@@ -44,27 +41,30 @@ public class LoanApplicationService {
|
||||
httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1);
|
||||
|
||||
// tag::client_call_server[]
|
||||
ResponseEntity<FraudServiceResponse> response =
|
||||
this.restTemplate.exchange(this.fraudUrl + "/fraudcheck", HttpMethod.PUT,
|
||||
new HttpEntity<>(request, httpHeaders),
|
||||
FraudServiceResponse.class);
|
||||
ResponseEntity<FraudServiceResponse> response = this.restTemplate.exchange(
|
||||
this.fraudUrl + "/fraudcheck", HttpMethod.PUT,
|
||||
new HttpEntity<>(request, httpHeaders), FraudServiceResponse.class);
|
||||
// end::client_call_server[]
|
||||
|
||||
return response.getBody();
|
||||
}
|
||||
|
||||
private LoanApplicationResult buildResponseFromFraudResult(FraudServiceResponse response) {
|
||||
private LoanApplicationResult buildResponseFromFraudResult(
|
||||
FraudServiceResponse response) {
|
||||
LoanApplicationStatus applicationStatus = null;
|
||||
if (FraudCheckStatus.OK == response.getFraudCheckStatus()) {
|
||||
applicationStatus = LoanApplicationStatus.LOAN_APPLIED;
|
||||
} else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) {
|
||||
}
|
||||
else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) {
|
||||
applicationStatus = LoanApplicationStatus.LOAN_APPLICATION_REJECTED;
|
||||
}
|
||||
|
||||
return new LoanApplicationResult(applicationStatus, response.getRejectionReason());
|
||||
return new LoanApplicationResult(applicationStatus,
|
||||
response.getRejectionReason());
|
||||
}
|
||||
|
||||
public void setFraudUrl(String fraudUrl) {
|
||||
this.fraudUrl = fraudUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.example.loan.model;
|
||||
public class Client {
|
||||
|
||||
private String clientId;
|
||||
|
||||
|
||||
public Client() {
|
||||
}
|
||||
|
||||
@@ -18,4 +18,5 @@ public class Client {
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.loan.model;
|
||||
|
||||
public enum FraudCheckStatus {
|
||||
|
||||
OK, FRAUD
|
||||
|
||||
}
|
||||
|
||||
@@ -31,4 +31,5 @@ public class FraudServiceRequest {
|
||||
public void setLoanAmount(BigDecimal loanAmount) {
|
||||
this.loanAmount = loanAmount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,4 +24,5 @@ public class FraudServiceResponse {
|
||||
public void setRejectionReason(String rejectionReason) {
|
||||
this.rejectionReason = rejectionReason;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,4 +41,5 @@ public class LoanApplication {
|
||||
public void setLoanApplicationId(String loanApplicationId) {
|
||||
this.loanApplicationId = loanApplicationId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ public class LoanApplicationResult {
|
||||
public LoanApplicationResult() {
|
||||
}
|
||||
|
||||
public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, String rejectionReason) {
|
||||
public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus,
|
||||
String rejectionReason) {
|
||||
this.loanApplicationStatus = loanApplicationStatus;
|
||||
this.rejectionReason = rejectionReason;
|
||||
}
|
||||
@@ -29,4 +30,5 @@ public class LoanApplicationResult {
|
||||
public void setRejectionReason(String rejectionReason) {
|
||||
this.rejectionReason = rejectionReason;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.loan.model;
|
||||
|
||||
public enum LoanApplicationStatus {
|
||||
|
||||
LOAN_APPLIED, LOAN_APPLICATION_REJECTED
|
||||
|
||||
}
|
||||
|
||||
@@ -35,30 +35,34 @@ public class FailFastLoanApplicationServiceTests {
|
||||
@Test
|
||||
public void shouldFailToStartContextWhenNoStubCanBeFound() {
|
||||
// When
|
||||
final Throwable throwable = catchThrowable(() -> new SpringApplicationBuilder(Application.class, StubRunnerConfiguration.class)
|
||||
.properties(ImmutableMap.of(
|
||||
"stubrunner.stubsMode", "REMOTE",
|
||||
"stubrunner.repositoryRoot", "classpath:m2repo/repository/",
|
||||
"stubrunner.ids", new String[]{"org.springframework.cloud.contract.verifier.stubs:should-not-be-found"}))
|
||||
.run());
|
||||
final Throwable throwable = catchThrowable(() -> new SpringApplicationBuilder(
|
||||
Application.class, StubRunnerConfiguration.class)
|
||||
.properties(ImmutableMap.of("stubrunner.stubsMode", "REMOTE",
|
||||
"stubrunner.repositoryRoot",
|
||||
"classpath:m2repo/repository/", "stubrunner.ids",
|
||||
new String[] {
|
||||
"org.springframework.cloud.contract.verifier.stubs:should-not-be-found" }))
|
||||
.run());
|
||||
|
||||
// Then
|
||||
assertThat(throwable).isInstanceOf(BeanCreationException.class);
|
||||
assertThat(throwable.getCause()).isInstanceOf(BeanInstantiationException.class);
|
||||
assertThat(throwable.getCause().getCause())
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("For groupId [org.springframework.cloud.contract.verifier.stubs] artifactId [should-not-be-found] "
|
||||
+ "and classifier [stubs] the version was not resolved! The following exceptions took place");
|
||||
.isInstanceOf(IllegalArgumentException.class).hasMessageContaining(
|
||||
"For groupId [org.springframework.cloud.contract.verifier.stubs] artifactId [should-not-be-found] "
|
||||
+ "and classifier [stubs] the version was not resolved! The following exceptions took place");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotTryAndWorkOfflineWhenRemoteModeIsOn() {
|
||||
// When
|
||||
final Throwable throwable = catchThrowable(() -> new SpringApplicationBuilder(Application.class, StubRunnerConfiguration.class)
|
||||
.properties(ImmutableMap.of(
|
||||
"stubrunner.stubsMode", "CLASSPATH",
|
||||
"stubrunner.ids", new String[]{"org.springframework.cloud.contract.verifier.stubs:should-not-be-found"}))
|
||||
.run());
|
||||
final Throwable throwable = catchThrowable(() -> new SpringApplicationBuilder(
|
||||
Application.class, StubRunnerConfiguration.class)
|
||||
.properties(ImmutableMap.of("stubrunner.stubsMode", "CLASSPATH",
|
||||
"stubrunner.ids",
|
||||
new String[] {
|
||||
"org.springframework.cloud.contract.verifier.stubs:should-not-be-found" }))
|
||||
.run());
|
||||
|
||||
// Then
|
||||
assertThat(throwable).isInstanceOf(BeanCreationException.class);
|
||||
|
||||
@@ -22,26 +22,33 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
// tag::autoconfigure_stubrunner[]
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureStubRunner(repositoryRoot = "classpath:m2repo/repository/",
|
||||
ids = { "org.springframework.cloud.contract.verifier.stubs:contextPathFraudDetectionServer" },
|
||||
stubsMode = StubRunnerProperties.StubsMode.REMOTE)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureStubRunner(repositoryRoot = "classpath:m2repo/repository/", ids = {
|
||||
"org.springframework.cloud.contract.verifier.stubs:contextPathFraudDetectionServer" }, stubsMode = StubRunnerProperties.StubsMode.REMOTE)
|
||||
public class LoanApplicationServiceTests {
|
||||
// end::autoconfigure_stubrunner[]
|
||||
|
||||
@Autowired private LoanApplicationService service;
|
||||
@Autowired private StubFinder stubFinder;
|
||||
@LocalServerPort Integer port;
|
||||
// end::autoconfigure_stubrunner[]
|
||||
|
||||
@Autowired
|
||||
private LoanApplicationService service;
|
||||
|
||||
@Autowired
|
||||
private StubFinder stubFinder;
|
||||
|
||||
@LocalServerPort
|
||||
Integer port;
|
||||
|
||||
@Before
|
||||
public void setPort() {
|
||||
this.service.setFraudUrl(this.stubFinder.findStubUrl("contextPathFraudDetectionServer").toString() + "/fraud-path/");
|
||||
this.service.setFraudUrl(
|
||||
this.stubFinder.findStubUrl("contextPathFraudDetectionServer").toString()
|
||||
+ "/fraud-path/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldStartThisAppWithContextPath() {
|
||||
String response = new RestTemplate()
|
||||
.getForObject("http://localhost:" + this.port + "/my-path/foo", String.class);
|
||||
String response = new RestTemplate().getForObject(
|
||||
"http://localhost:" + this.port + "/my-path/foo", String.class);
|
||||
|
||||
assertThat(response).isNotEmpty();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user