diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ScmStubDownloaderBuilder.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ScmStubDownloaderBuilder.java index be38cc3781..ced94adf83 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ScmStubDownloaderBuilder.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/ScmStubDownloaderBuilder.java @@ -31,6 +31,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; @@ -295,8 +296,9 @@ class FileWalker extends SimpleFileVisitor { Path foundFile; FileWalker(StubConfiguration stubConfiguration) { - this.latestSnapshotVersion = LATEST.stream().anyMatch(s -> s.equals(stubConfiguration.version.toLowerCase())); - this.latestReleaseVersion = RELEASE.equals(stubConfiguration.version.toLowerCase()); + this.latestSnapshotVersion = LATEST.stream() + .anyMatch(s -> s.equals(stubConfiguration.version.toLowerCase(Locale.ROOT))); + this.latestReleaseVersion = RELEASE.equals(stubConfiguration.version.toLowerCase(Locale.ROOT)); this.matcherWithDot = FileSystems.getDefault().getPathMatcher("glob:" + matcherGlob(stubConfiguration, ".")); this.matcherWithoutDot = FileSystems.getDefault().getPathMatcher("glob:" + matcherGlob(stubConfiguration, "/")); } @@ -368,12 +370,12 @@ private DefaultArtifactVersionWrapper replaceWithSnapshotIfSameVersions( private File folderWithPredefinedName(File[] files) { if (this.latestSnapshotVersion) { return Arrays.stream(files) - .filter(file -> LATEST.stream().anyMatch(s -> s.equals(file.getName().toLowerCase()))) + .filter(file -> LATEST.stream().anyMatch(s -> s.equals(file.getName().toLowerCase(Locale.ROOT)))) .findFirst() .orElse(null); } return Arrays.stream(files) - .filter(file -> RELEASE.equals(file.getName().toLowerCase())) + .filter(file -> RELEASE.equals(file.getName().toLowerCase(Locale.ROOT))) .findFirst() .orElse(null); } diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubConfiguration.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubConfiguration.java index a5d1dcd96b..7de7a84f05 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubConfiguration.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubConfiguration.java @@ -16,6 +16,8 @@ package org.springframework.cloud.contract.stubrunner; +import java.util.Locale; + import org.springframework.util.StringUtils; /** @@ -128,7 +130,7 @@ public boolean groupIdAndArtifactMatches(String ivyNotationAsString) { * @return {@code true} for a snapshot or a LATEST (+) version. */ public boolean isVersionChanging() { - return DEFAULT_VERSION.equals(this.version) || this.version.toLowerCase().contains("snapshot"); + return DEFAULT_VERSION.equals(this.version) || this.version.toLowerCase(Locale.ROOT).contains("snapshot"); } public String getGroupId() { diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java index ad7d9afab6..9d08d064b9 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerOptions.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.Collection; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.Properties; import java.util.Set; @@ -213,7 +214,7 @@ private static Map stubRunnerProps() { Set propertyNames = properties.stringPropertyNames(); propertyNames.stream() // stubrunner.properties.foo.bar=baz - .filter(s -> s.toLowerCase().startsWith("stubrunner.properties")) + .filter(s -> s.toLowerCase(Locale.ROOT).startsWith("stubrunner.properties")) // foo.bar=baz .forEach(s -> map.put(s.substring("stubrunner.properties".length() + 1), System.getProperty(s))); return map; diff --git a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtils.java b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtils.java index 6b9e437e6d..2fef2a1e0a 100644 --- a/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtils.java +++ b/spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/StubRunnerPropertyUtils.java @@ -17,6 +17,7 @@ package org.springframework.cloud.contract.stubrunner; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import org.apache.commons.logging.Log; @@ -81,7 +82,7 @@ public static String getProperty(Map options, String propName) { } private static String appendPrefixIfNecessary(String prop) { - if (prop.toLowerCase().startsWith("stubrunner")) { + if (prop.toLowerCase(Locale.ROOT).startsWith("stubrunner")) { return prop; } return STUBRUNNER_PROPERTIES + "." + prop; @@ -95,7 +96,7 @@ private static String doGetProp(String stubRunnerProp) { } return systemProp; } - String convertedEnvProp = stubRunnerProp.replaceAll("\\.", "_").replaceAll("-", "_").toUpperCase(); + String convertedEnvProp = stubRunnerProp.replaceAll("\\.", "_").replaceAll("-", "_").toUpperCase(Locale.ROOT); String envVar = FETCHER.envVar(convertedEnvProp); if (log.isTraceEnabled()) { log.trace("Environment variable [" + convertedEnvProp + "] has value [" + envVar + "]"); diff --git a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/java/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.java b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/java/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.java index c6aa5a8bfd..93c493b6f0 100644 --- a/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/java/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.java +++ b/spring-cloud-contract-tools/spring-cloud-contract-gradle-plugin/src/main/java/org/springframework/cloud/contract/verifier/plugin/ContractVerifierExtension.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import javax.inject.Inject; @@ -269,7 +270,7 @@ public void setTestFramework(TestFramework testFramework) { } public void setTestFramework(String testFramework) { - this.testFramework.set(TestFramework.valueOf(testFramework.toUpperCase())); + this.testFramework.set(TestFramework.valueOf(testFramework.toUpperCase(Locale.ROOT))); } public Property getTestMode() { @@ -281,7 +282,7 @@ public void setTestMode(TestMode testMode) { } public void setTestMode(String testMode) { - this.testMode.set(TestMode.valueOf(testMode.toUpperCase())); + this.testMode.set(TestMode.valueOf(testMode.toUpperCase(Locale.ROOT))); } public Property getBasePackageForTests() { @@ -469,7 +470,7 @@ public void setContractsMode(StubRunnerProperties.StubsMode contractsMode) { } public void setContractsMode(String contractsMode) { - this.contractsMode.set(StubRunnerProperties.StubsMode.valueOf(contractsMode.toUpperCase())); + this.contractsMode.set(StubRunnerProperties.StubsMode.valueOf(contractsMode.toUpperCase(Locale.ROOT))); } public Property getPackageWithBaseClasses() { diff --git a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/BodyReader.java b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/BodyReader.java index 2ce5a040b6..4e0d2dd3de 100644 --- a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/BodyReader.java +++ b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/BodyReader.java @@ -23,6 +23,7 @@ import java.nio.file.Path; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Map; import org.apache.commons.logging.Log; @@ -71,7 +72,7 @@ void storeContractAsYaml(SingleContractMetadata metadata) { private String byteBodyToAFileForTestMethod(SingleContractMetadata metadata, FromFileProperty property, CommunicationType side) { GeneratedClassDataForMethod classDataForMethod = classDataForMethod(metadata); - String newFileName = classDataForMethod.getMethodName() + "_" + side.name().toLowerCase() + "_" + String newFileName = classDataForMethod.getMethodName() + "_" + side.name().toLowerCase(Locale.ROOT) + "_" + property.fileName(); writeFileForBothIdeAndBuildTool(metadata, property.asBytes(), newFileName); return newFileName; diff --git a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/CustomModeMethodWithUrlGiven.java b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/CustomModeMethodWithUrlGiven.java index ca91eaab39..ee74be2876 100644 --- a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/CustomModeMethodWithUrlGiven.java +++ b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/CustomModeMethodWithUrlGiven.java @@ -16,6 +16,8 @@ package org.springframework.cloud.contract.verifier.builder; +import java.util.Locale; + import org.springframework.cloud.contract.spec.internal.ExecutionProperty; import org.springframework.cloud.contract.spec.internal.Request; import org.springframework.cloud.contract.spec.internal.Url; @@ -51,7 +53,7 @@ private Url getUrl(Request request) { private void addUrl(Url buildUrl, Request request) { Object testSideUrl = MapConverter.getTestSideValues(buildUrl); - String method = request.getMethod().getServerValue().toString().toLowerCase(); + String method = request.getMethod().getServerValue().toString().toLowerCase(Locale.ROOT); String url = testSideUrl.toString(); if (!(testSideUrl instanceof ExecutionProperty)) { url = this.bodyParser.quotedShortText(testSideUrl.toString()); diff --git a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/JaxRsRequestMethodWhen.java b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/JaxRsRequestMethodWhen.java index 82580a5bd3..5ad6bcf75e 100644 --- a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/JaxRsRequestMethodWhen.java +++ b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/JaxRsRequestMethodWhen.java @@ -16,6 +16,8 @@ package org.springframework.cloud.contract.verifier.builder; +import java.util.Locale; + import org.springframework.cloud.contract.spec.internal.ExecutionProperty; import org.springframework.cloud.contract.spec.internal.FromFileProperty; import org.springframework.cloud.contract.spec.internal.Request; @@ -43,7 +45,7 @@ public MethodVisitor apply(SingleContractMetadata metadata) { void appendMethodAndBody(SingleContractMetadata metadata) { Request request = metadata.getContract().getRequest(); ContentType type = metadata.getInputTestContentType(); - String method = request.getMethod().getServerValue().toString().toLowerCase(); + String method = request.getMethod().getServerValue().toString().toLowerCase(Locale.ROOT); if (request.getBody() != null) { String contentType = StringUtils.hasText(metadata.getDefinedInputTestContentType()) ? metadata.getDefinedInputTestContentType() : type.getMimeType(); @@ -61,11 +63,11 @@ else if (body instanceof FromFileProperty) { else { value = "\"" + requestBodyAsString(metadata) + "\""; } - this.blockBuilder.addIndented( - ".build(\"" + method.toUpperCase() + "\", entity(" + value + ", \"" + contentType + "\"))"); + this.blockBuilder.addIndented(".build(\"" + method.toUpperCase(Locale.ROOT) + "\", entity(" + value + ", \"" + + contentType + "\"))"); } else { - this.blockBuilder.addIndented(".build(\"" + method.toUpperCase() + "\")"); + this.blockBuilder.addIndented(".build(\"" + method.toUpperCase(Locale.ROOT) + "\")"); } } diff --git a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/MockMvcUrlWhen.java b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/MockMvcUrlWhen.java index 8c873f5690..3deeefbf7d 100644 --- a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/MockMvcUrlWhen.java +++ b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/builder/MockMvcUrlWhen.java @@ -16,6 +16,8 @@ package org.springframework.cloud.contract.verifier.builder; +import java.util.Locale; + import org.springframework.cloud.contract.spec.internal.ExecutionProperty; import org.springframework.cloud.contract.spec.internal.Request; import org.springframework.cloud.contract.spec.internal.Url; @@ -53,7 +55,7 @@ private Url getUrl(Request request) { private void addUrl(Url buildUrl, Request request) { Object testSideUrl = MapConverter.getTestSideValues(buildUrl); - String method = request.getMethod().getServerValue().toString().toLowerCase(); + String method = request.getMethod().getServerValue().toString().toLowerCase(Locale.ROOT); String url = testSideUrl.toString(); if (!(testSideUrl instanceof ExecutionProperty)) { url = this.bodyParser.quotedShortText(testSideUrl.toString()); diff --git a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/converter/YamlContract.java b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/converter/YamlContract.java index 2fa273c4a1..e7ddb4f456 100644 --- a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/converter/YamlContract.java +++ b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/converter/YamlContract.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; @@ -273,7 +274,7 @@ static MatchingType from(String string) { return Arrays.stream(values()) .filter(matchingType -> matchingType.name() .replace("_", "") - .equalsIgnoreCase(string.toLowerCase().replace("_", ""))) + .equalsIgnoreCase(string.toLowerCase(Locale.ROOT).replace("_", ""))) .findFirst() .orElse(null); } diff --git a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/http/OkHttpHttpVerifier.java b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/http/OkHttpHttpVerifier.java index 5e701ad220..2b891df91b 100644 --- a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/http/OkHttpHttpVerifier.java +++ b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/http/OkHttpHttpVerifier.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; @@ -78,7 +79,7 @@ public Response exchange(Request request) { } private String url(Request request) { - String url = request.scheme().name().toLowerCase() + ":" + this.hostAndPort + String url = request.scheme().name().toLowerCase(Locale.ROOT) + ":" + this.hostAndPort + (request.path().startsWith("/") ? request.path() : "/" + request.path()); if (!request.queryParams().isEmpty()) { return url + "?" diff --git a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/http/Request.java b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/http/Request.java index 41e3bd4407..87a0ed361c 100644 --- a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/http/Request.java +++ b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/http/Request.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import org.springframework.cloud.contract.spec.internal.HttpMethods; @@ -69,7 +70,7 @@ public class Request { public String contentType() { Object value = this.headers.entrySet() .stream() - .filter(e -> e.getKey().toLowerCase().equals("content-type")) + .filter(e -> e.getKey().toLowerCase(Locale.ROOT).equals("content-type")) .findFirst() .orElse(new AbstractMap.SimpleEntry<>("", null)) .getValue(); @@ -169,7 +170,7 @@ public static class MethodBuilder { * @return builder */ public Request.Builder method(String method, String path) { - return new Request.Builder(HttpMethods.HttpMethod.valueOf(method.toUpperCase()), path); + return new Request.Builder(HttpMethods.HttpMethod.valueOf(method.toUpperCase(Locale.ROOT)), path); } /** diff --git a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/DestinationResolver.java b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/DestinationResolver.java index 9344551fd3..be50b8aa6c 100644 --- a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/DestinationResolver.java +++ b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/messaging/stream/DestinationResolver.java @@ -17,6 +17,7 @@ package org.springframework.cloud.contract.verifier.messaging.stream; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import org.apache.commons.logging.Log; @@ -60,9 +61,9 @@ else if (channels.size() > 0) { log.debug("Found following channels [" + channels + "] for destination [" + destination + "]. " + "Will pick the one that matches the default channel name or the first one if none is matching"); } - String defaultChannelName = channels.get(defaultChannel.name().toLowerCase()); + String defaultChannelName = channels.get(defaultChannel.name().toLowerCase(Locale.ROOT)); String matchingChannelName = StringUtils.hasText(defaultChannelName) - ? defaultChannel.name().toLowerCase() : channels.keySet().iterator().next(); + ? defaultChannel.name().toLowerCase(Locale.ROOT) : channels.keySet().iterator().next(); if (log.isDebugEnabled()) { log.debug("Picked channel name is [" + matchingChannelName + "]"); } diff --git a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/util/NamesUtil.java b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/util/NamesUtil.java index 2326db7679..a01075a417 100644 --- a/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/util/NamesUtil.java +++ b/spring-cloud-contract-verifier/src/main/java/org/springframework/cloud/contract/verifier/util/NamesUtil.java @@ -26,6 +26,7 @@ import java.util.ArrayDeque; import java.util.Collection; import java.util.Deque; +import java.util.Locale; /** * A utility class that helps to convert names. @@ -104,7 +105,7 @@ public static String camelCase(String className) { if (isEmpty(className)) { return className; } - String firstChar = className.substring(0, 1).toLowerCase(); + String firstChar = className.substring(0, 1).toLowerCase(Locale.ROOT); return firstChar + className.substring(1); } @@ -115,7 +116,7 @@ public static String capitalize(String className) { if (isEmpty(className)) { return className; } - String firstChar = className.substring(0, 1).toUpperCase(); + String firstChar = className.substring(0, 1).toUpperCase(Locale.ROOT); return firstChar + className.substring(1); } diff --git a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockSnippet.java b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockSnippet.java index 8140d691f7..45c2995142 100644 --- a/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockSnippet.java +++ b/spring-cloud-contract-wiremock/src/main/java/org/springframework/cloud/contract/wiremock/restdocs/WireMockSnippet.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.Locale; import java.util.Set; import java.util.regex.Pattern; @@ -169,7 +170,7 @@ private MappingBuilder requestHeaders(MappingBuilder request, Operation operatio org.springframework.http.HttpHeaders headers = operation.getRequest().getHeaders(); // TODO: whitelist headers for (String name : headers.keySet()) { - if (!this.headerBlackList.contains(name.toLowerCase())) { + if (!this.headerBlackList.contains(name.toLowerCase(Locale.ROOT))) { if ("content-type".equalsIgnoreCase(name) && this.contentType != null) { continue; } @@ -239,7 +240,7 @@ private HttpHeaders responseHeaders(Operation operation) { org.springframework.http.HttpHeaders headers = operation.getResponse().getHeaders(); HttpHeaders result = new HttpHeaders(); for (String name : headers.keySet()) { - if (!this.headerBlackList.contains(name.toLowerCase())) { + if (!this.headerBlackList.contains(name.toLowerCase(Locale.ROOT))) { result = result.plus(new HttpHeader(name, headers.get(name))); } }