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:
Marcin Grzejszczak
2015-11-15 18:32:08 +00:00
4 changed files with 28 additions and 4 deletions

View File

@@ -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;
}
}

View File

@@ -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 =

View File

@@ -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;
}
}

View File

@@ -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 =