Not running HTTP server if there are no mappings / contracts
without this change we're forcing the users to turn on web components even they don't use them with this change if there are no mappings or contracts then we do not start the web server fixes #279
This commit is contained in:
@@ -231,7 +231,7 @@ class StubRunnerExecutor implements StubFinder {
|
||||
final List<WiremockMappingDescriptor> mappings = repository.getProjectDescriptors();
|
||||
final Collection<Contract> contracts = repository.contracts;
|
||||
Integer port = stubRunnerOptions.port(stubConfiguration);
|
||||
if (!contracts.isEmpty() && !hasRequest(contracts)) {
|
||||
if (!hasRequest(contracts) && mappings.isEmpty()) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("There are no HTTP related contracts. Won't start any servers");
|
||||
}
|
||||
@@ -239,7 +239,7 @@ class StubRunnerExecutor implements StubFinder {
|
||||
return;
|
||||
}
|
||||
if (port != null && port >= 0) {
|
||||
this.stubServer = new StubServer(stubConfiguration, mappings, contracts, new WireMockHttpServerStub(port));
|
||||
this.stubServer = new StubServer(stubConfiguration, mappings, contracts, new WireMockHttpServerStub(port)).start();
|
||||
}
|
||||
else {
|
||||
this.stubServer = this.portScanner.tryToExecuteWithFreePort(new PortCallback<StubServer>() {
|
||||
@@ -248,12 +248,14 @@ class StubRunnerExecutor implements StubFinder {
|
||||
return new StubServer(stubConfiguration, mappings, contracts,
|
||||
new WireMockHttpServerStub(availablePort));
|
||||
}
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
this.stubServer = this.stubServer.start();
|
||||
}
|
||||
|
||||
private boolean hasRequest(Collection<Contract> contracts) {
|
||||
if (contracts.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (Contract contract : contracts) {
|
||||
if (contract.getRequest() != null) {
|
||||
return true;
|
||||
|
||||
@@ -131,6 +131,19 @@ class StubRunnerExecutorSpec extends Specification {
|
||||
executor.shutdown()
|
||||
}
|
||||
|
||||
def 'should not start http server if no contracts or mappings are found'() {
|
||||
given:
|
||||
def stubConf = new StubConfiguration('asd', 'asd', 'asd', '')
|
||||
StubRunnerExecutor executor = new StubRunnerExecutor(portScanner)
|
||||
when:
|
||||
RunningStubs stubs = executor.runStubs(stubRunnerOptions,
|
||||
new StubRepository(new File('src/test/resources/emptyrepo')), stubConf)
|
||||
then:
|
||||
stubs.getPort('asd') == -1
|
||||
cleanup:
|
||||
executor.shutdown()
|
||||
}
|
||||
|
||||
Map<StubConfiguration, Integer> stubIdsWithPortsFromString(String stubIdsToPortMapping) {
|
||||
return stubIdsToPortMapping.split(',').collectEntries { String entry ->
|
||||
return StubsParser.fromStringWithPort(entry)
|
||||
|
||||
Reference in New Issue
Block a user