Merge pull request #174 from Codearte/issues/147-made-tests-use-random-ports
[#147] Made tests use random ports. Fixes #147
This commit is contained in:
@@ -21,6 +21,8 @@ public class LoanApplicationService {
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
private Integer port = 8080;
|
||||
|
||||
public LoanApplicationService() {
|
||||
this.restTemplate = new RestTemplate();
|
||||
}
|
||||
@@ -41,7 +43,7 @@ public class LoanApplicationService {
|
||||
httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1);
|
||||
|
||||
ResponseEntity<FraudServiceResponse> response =
|
||||
restTemplate.exchange("http://localhost:8080/fraudcheck", HttpMethod.PUT,
|
||||
restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT,
|
||||
new HttpEntity<>(request, httpHeaders),
|
||||
FraudServiceResponse.class);
|
||||
|
||||
@@ -59,4 +61,8 @@ public class LoanApplicationService {
|
||||
return new LoanApplicationResult(applicationStatus, response.getRejectionReason());
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,13 +17,19 @@ import spock.lang.Specification
|
||||
@ContextConfiguration(loader = SpringApplicationContextLoader, classes = Application)
|
||||
class LoanApplicationServiceSpec extends Specification {
|
||||
|
||||
public static Integer port = org.springframework.util.SocketUtils.findAvailableTcpPort()
|
||||
|
||||
@ClassRule
|
||||
@Shared
|
||||
WireMockClassRule wireMockRule = new WireMockClassRule()
|
||||
WireMockClassRule wireMockRule = new WireMockClassRule(port)
|
||||
|
||||
@Autowired
|
||||
LoanApplicationService sut
|
||||
|
||||
def setup() {
|
||||
sut.port = port
|
||||
}
|
||||
|
||||
def 'should successfully apply for loan'() {
|
||||
given:
|
||||
LoanApplication application =
|
||||
|
||||
@@ -21,6 +21,8 @@ public class LoanApplicationService {
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
private Integer port = 8080;
|
||||
|
||||
public LoanApplicationService() {
|
||||
this.restTemplate = new RestTemplate();
|
||||
}
|
||||
@@ -41,7 +43,7 @@ public class LoanApplicationService {
|
||||
httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1);
|
||||
|
||||
ResponseEntity<FraudServiceResponse> response =
|
||||
restTemplate.exchange("http://localhost:8080/fraudcheck", HttpMethod.PUT,
|
||||
restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT,
|
||||
new HttpEntity<>(request, httpHeaders),
|
||||
FraudServiceResponse.class);
|
||||
|
||||
@@ -59,4 +61,8 @@ public class LoanApplicationService {
|
||||
return new LoanApplicationResult(applicationStatus, response.getRejectionReason());
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,13 +17,19 @@ import spock.lang.Specification
|
||||
@ContextConfiguration(loader = SpringApplicationContextLoader, classes = Application)
|
||||
class LoanApplicationServiceSpec extends Specification {
|
||||
|
||||
public static Integer port = org.springframework.util.SocketUtils.findAvailableTcpPort()
|
||||
|
||||
@ClassRule
|
||||
@Shared
|
||||
WireMockClassRule wireMockRule = new WireMockClassRule()
|
||||
WireMockClassRule wireMockRule = new WireMockClassRule(port)
|
||||
|
||||
@Autowired
|
||||
LoanApplicationService sut
|
||||
|
||||
def setup() {
|
||||
sut.port = port
|
||||
}
|
||||
|
||||
def 'should successfully apply for loan'() {
|
||||
given:
|
||||
LoanApplication application =
|
||||
|
||||
Reference in New Issue
Block a user