Fixed code style issues

This commit is contained in:
Marcin Grzejszczak
2016-08-12 11:46:41 +02:00
parent 24c0de9b80
commit c7665db7d9
16 changed files with 84 additions and 46 deletions

View File

@@ -63,15 +63,19 @@ class AvailablePortScanner {
return executeLogicForAvailablePort(portToScan, closure);
}
catch (IOException exception) {
log.debug("Failed to execute callback (try: " + i + "/" + maxRetryCount
+ ")", exception);
if (log.isDebugEnabled()) {
log.debug("Failed to execute callback (try: " + i + "/" + maxRetryCount
+ ")", exception);
}
}
}
throw new NoPortAvailableException(minPortNumber, maxPortNumber);
}
private <T> T executeLogicForAvailablePort(int portToScan, PortCallback<T> closure) throws IOException {
log.debug("Trying to execute closure with port [$portToScan]");
if (log.isDebugEnabled()) {
log.debug("Trying to execute closure with port [" + portToScan + "]");
}
return closure.call(portToScan);
}

View File

@@ -193,7 +193,9 @@ class StubRunnerExecutor implements StubFinder {
final Collection<Contract> contracts = repository.contracts;
Integer port = stubRunnerOptions.port(stubConfiguration);
if (!contracts.isEmpty() && !hasRequest(contracts)) {
log.debug("There are no HTTP related contracts. Won't start any servers");
if (log.isDebugEnabled()) {
log.debug("There are no HTTP related contracts. Won't start any servers");
}
stubServer = new StubServer(stubConfiguration, mappings, contracts, new NoOpHttpServerStub());
return;
}

View File

@@ -92,7 +92,9 @@ public class StubRunnerMain {
private void execute() {
try {
log.debug("Launching StubRunner with args: " + arguments);
if (log.isDebugEnabled()) {
log.debug("Launching StubRunner with args: " + arguments);
}
// TODO: Pass StubsToRun either from String or File
BatchStubRunner stubRunner = new BatchStubRunnerFactory(
arguments.getStubRunnerOptions()).buildBatchStubRunner();

View File

@@ -59,8 +59,10 @@ class StubServer {
if (httpServerStub.isRunning()) {
return httpServerStub.port();
}
log.debug("The HTTP Server stub is not running... That means that the " +
"artifact is running a messaging module. Returning back -1 value of the port.");
if (log.isDebugEnabled()) {
log.debug("The HTTP Server stub is not running... That means that the " +
"artifact is running a messaging module. Returning back -1 value of the port.");
}
return -1;
}
@@ -96,7 +98,9 @@ class StubServer {
for (WiremockMappingDescriptor mappingDescriptor : sortedMappings) {
try {
wireMock.register(mappingDescriptor.getMapping());
log.debug("Registered stub mappings from [" + mappingDescriptor.descriptor + "]");
if (log.isDebugEnabled()) {
log.debug("Registered stub mappings from [" + mappingDescriptor.descriptor + "]");
}
} catch (Exception e) {
log.warn("Failed to register the stub mapping ["+ mappingDescriptor + "]", e);
}

View File

@@ -126,14 +126,18 @@ public class StubRunnerStreamConfiguration {
for (Map.Entry<String, BindingProperties> entry : channelBindingServiceProperties
.getBindings().entrySet()) {
if (entry.getValue().getDestination().equals(destination)) {
log.debug("Found a channel named [{}] with destination [{}]",
entry.getKey(), destination);
if (log.isDebugEnabled()) {
log.debug("Found a channel named [{}] with destination [{}]",
entry.getKey(), destination);
}
return entry.getKey();
}
}
log.debug(
"No destination named [{}] was found. Assuming that the destination equals the channel name",
destination);
if (log.isDebugEnabled()) {
log.debug(
"No destination named [{}] was found. Assuming that the destination equals the channel name",
destination);
}
return destination;
}

View File

@@ -54,7 +54,9 @@ public class TriggerController {
stubFinder.trigger(label);
return ResponseEntity.ok().body(Collections.<String, Collection<String>>emptyMap());
} catch (Exception e) {
log.debug("Exception occurred while trying to return " + label + " label", e);
if (log.isDebugEnabled()) {
log.debug("Exception occurred while trying to return " + label + " label", e);
}
return new ResponseEntity<>(stubFinder.labels(), HttpStatus.NOT_FOUND);
}
}
@@ -65,7 +67,9 @@ public class TriggerController {
stubFinder.trigger(ivyNotation, label);
return ResponseEntity.ok().body(Collections.<String, Collection<String>>emptyMap());
} catch (Exception e) {
log.debug("Exception occurred while trying to return " + label + " label", e);
if (log.isDebugEnabled()) {
log.debug("Exception occurred while trying to return " + label + " label", e);
}
return new ResponseEntity<>(stubFinder.labels(), HttpStatus.NOT_FOUND);
}
}

View File

@@ -16,19 +16,18 @@
package org.springframework.cloud.contract.stubrunner.junit;
import static org.assertj.core.api.BDDAssertions.then;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.Charset;
import org.assertj.core.api.BDDAssertions;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.springframework.util.StreamUtils;
import static org.assertj.core.api.BDDAssertions.then;
/**
* @author Marcin Grzejszczak
*/
@@ -57,9 +56,9 @@ public class StubRunnerRuleCustomPortJUnitTest {
then(rule.findStubUrl("loanIssuance")).isEqualTo(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull();
// and:
BDDAssertions.then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue();
BDDAssertions.then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue();
BDDAssertions.then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue();
then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue();
then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue();
then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue();
// and: 'Stubs were registered'
then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance");
then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer");

View File

@@ -16,19 +16,18 @@
package org.springframework.cloud.contract.stubrunner.junit;
import static org.assertj.core.api.BDDAssertions.then;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.Charset;
import org.assertj.core.api.BDDAssertions;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.springframework.util.StreamUtils;
import static org.assertj.core.api.BDDAssertions.then;
/**
* @author Marcin Grzejszczak
*/
@@ -57,9 +56,9 @@ public class StubRunnerRuleJUnitTest {
then(rule.findStubUrl("loanIssuance")).isEqualTo(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs", "loanIssuance"));
then(rule.findStubUrl("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isNotNull();
// and:
BDDAssertions.then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue();
BDDAssertions.then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue();
BDDAssertions.then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue();
then(rule.findAllRunningStubs().isPresent("loanIssuance")).isTrue();
then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs", "fraudDetectionServer")).isTrue();
then(rule.findAllRunningStubs().isPresent("org.springframework.cloud.contract.verifier.stubs:fraudDetectionServer")).isTrue();
// and: 'Stubs were registered'
then(httpGet(rule.findStubUrl("loanIssuance").toString() + "/name")).isEqualTo("loanIssuance");
then(httpGet(rule.findStubUrl("fraudDetectionServer").toString() + "/name")).isEqualTo("fraudDetectionServer");

View File

@@ -56,7 +56,9 @@ class RecursiveFilesConverter {
void processFiles() {
ContractFileScanner scanner = new ContractFileScanner(properties.contractsDslDir, properties.excludedFiles as Set, [] as Set)
ListMultimap<Path, ContractMetadata> contracts = scanner.findContracts()
log.debug("Found the following contracts $contracts")
if (log.isDebugEnabled()) {
log.debug("Found the following contracts $contracts")
}
contracts.asMap().entrySet().each { entry ->
entry.value.each { ContractMetadata contract ->
File sourceFile = contract.path.toFile()

View File

@@ -98,7 +98,7 @@ public class RunMojo extends AbstractMojo {
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip || skipTestOnly) {
getLog().info("Skipping verifier execution: spring.cloud.contract.verifier.skip=" + String.valueOf(skip));
getLog().info("Skipping verifier execution: spring.cloud.contract.verifier.skip=" + skip);
return;
}
BatchStubRunner batchStubRunner = null;

View File

@@ -41,7 +41,9 @@ public class RemoteStubRunner {
public BatchStubRunner run(StubRunnerOptions options, RepositorySystemSession repositorySystemSession) {
AetherStubDownloader stubDownloader = aetherStubDownloaderFactory.build(repositorySystemSession);
try {
log.debug("Launching StubRunner with args: " + String.valueOf(options));
if (log.isDebugEnabled()) {
log.debug("Launching StubRunner with args: " + options);
}
BatchStubRunner stubRunner = new BatchStubRunnerFactory(options,
stubDownloader).buildBatchStubRunner();
RunningStubs runningCollaborators = stubRunner.runStubs();

View File

@@ -54,7 +54,9 @@ class MethodBuilder {
* A factory method that creates a {@link MethodBuilder} for the given arguments
*/
static MethodBuilder createTestMethod(ContractMetadata contract, File stubsFile, Contract stubContent, ContractVerifierConfigProperties configProperties) {
log.debug("Stub content Groovy DSL [$stubContent]")
if (log.isDebugEnabled()) {
log.debug("Stub content Groovy DSL [$stubContent]")
}
String methodName = NamesUtil.camelCase(NamesUtil.toLastDot(NamesUtil.afterLast(stubsFile.path, File.separator)))
return new MethodBuilder(methodName, stubContent, configProperties, contract.ignored)
}

View File

@@ -120,7 +120,9 @@ class SingleTestGenerator {
private Map<ParsedDsl, TestType> mapContractsToTheirTestTypes(Collection<ContractMetadata> listOfFiles) {
return listOfFiles.collectEntries {
File stubsFile = it.path.toFile()
log.debug("Stub content from file [${stubsFile.text}]")
if (log.isDebugEnabled()) {
log.debug("Stub content from file [${stubsFile.text}]")
}
org.springframework.cloud.contract.spec.Contract stubContent = ContractVerifierDslConverter.convert(stubsFile)
TestType testType = (stubContent.input || stubContent.outputMessage) ? TestType.MESSAGING : TestType.HTTP
return [(new ParsedDsl(it, stubContent, stubsFile)): testType]
@@ -169,7 +171,9 @@ class SingleTestGenerator {
Class.forName(JSON_ASSERT_CLASS)
return true
} catch (ClassNotFoundException e) {
log.debug("JsonAssert is not present on classpath. Will not add a static import.")
if (log.isDebugEnabled()) {
log.debug("JsonAssert is not present on classpath. Will not add a static import.")
}
return false
}
}

View File

@@ -53,7 +53,9 @@ class JsonToJsonPathsConverter {
JsonToJsonPathsConverter() {
this.configProperties = new ContractVerifierConfigProperties()
log.debug("Creating JsonToJsonPaths converter with default properties")
if (log.isDebugEnabled()) {
log.debug("Creating JsonToJsonPaths converter with default properties")
}
}
public JsonPaths transformToJsonPathWithTestsSideValues(def json) {
@@ -146,14 +148,18 @@ class JsonToJsonPathsConverter {
configPropValue) {
addArraySizeCheck(key, value, closure)
} else {
log.debug("Turning off the incubating feature of JSON array check. " +
"System property [$systemPropValue]. Config property [$configPropValue]")
if (log.isDebugEnabled()) {
log.debug("Turning off the incubating feature of JSON array check. " +
"System property [$systemPropValue]. Config property [$configPropValue]")
}
return
}
}
private void addArraySizeCheck(MethodBufferingJsonVerifiable key, List value, Closure closure) {
log.debug("WARNING: Turning on the incubating feature of JSON array check")
if (log.isDebugEnabled()) {
log.debug("WARNING: Turning on the incubating feature of JSON array check")
}
if (isRootElement(key) || key.assertsConcreteValue()) {
if (value.size() > 0) {
closure(key.hasSize(value.size()), value)

View File

@@ -86,14 +86,18 @@ public class StreamStubMessages implements MessageVerifier<Message<?>> {
for (Map.Entry<String, BindingProperties> entry : channelBindingServiceProperties
.getBindings().entrySet()) {
if (entry.getValue().getDestination().equals(destination)) {
log.debug("Found a channel named [{}] with destination [{}]",
entry.getKey(), destination);
if (log.isDebugEnabled()) {
log.debug("Found a channel named [{}] with destination [{}]",
entry.getKey(), destination);
}
return entry.getKey();
}
}
log.debug(
"No destination named [{}] was found. Assuming that the destination equals the channel name",
destination);
if (log.isDebugEnabled()) {
log.debug(
"No destination named [{}] was found. Assuming that the destination equals the channel name",
destination);
}
return destination;
}

View File

@@ -16,8 +16,6 @@
package org.springframework.cloud.contract.wiremock.restdocs;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.HashMap;
@@ -41,6 +39,8 @@ import com.github.tomakehurst.wiremock.servlet.WireMockHttpServletRequestAdapter
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import com.jayway.jsonpath.JsonPath;
import static org.assertj.core.api.Assertions.assertThat;
public class ContractRequestHandler implements ResultHandler {
static final String ATTRIBUTE_NAME_CONFIGURATION = "org.springframework.restdocs.configuration";
@@ -134,9 +134,9 @@ public class ContractRequestHandler implements ResultHandler {
private void compile(String expression, Object... args) {
org.springframework.util.Assert.hasText(
(expression == null ? null : expression.toString()),
(expression == null ? null : expression),
"expression must not be null or empty");
expression = String.format(expression.toString(), args);
expression = String.format(expression, args);
jsonPaths.put(expression, JsonPath.compile(expression));
}