Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1933 - Upgrading Wiremock to 3.3.0 #2092

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<handlebars.version>4.3.1</handlebars.version>
<jgit.version>6.7.0.202309050840-r</jgit.version>
<javax-inject.version>1</javax-inject.version>
<jakarta-annotation.version>2.1.1</jakarta-annotation.version>
<json-unit-assertj.version>2.38.0</json-unit-assertj.version>
<rest-assured.version>5.2.1</rest-assured.version>
<slf4j.version>[2.0.0,)</slf4j.version>
Expand Down Expand Up @@ -238,6 +239,11 @@
<artifactId>javax.inject</artifactId>
<version>${javax-inject.version}</version>
</dependency>
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>${jakarta-annotation.version}</version>
</dependency>

<!-- Git Stub Downloader-->
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions spring-cloud-contract-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<name>spring-cloud-contract-dependencies</name>
<description>Spring Cloud Contract Dependencies</description>
<properties>
<wiremock.version>2.35.1</wiremock.version>
<wiremock.version>3.3.0</wiremock.version>
<jsonassert.version>0.8.0</jsonassert.version>
</properties>
<dependencyManagement>
Expand Down Expand Up @@ -96,8 +96,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8-standalone</artifactId>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>${wiremock.version}</version>
</dependency>
<!-- Leaving this for backward compatibility -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -42,14 +41,12 @@
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import wiremock.com.github.jknack.handlebars.Helper;

import org.springframework.cloud.contract.stubrunner.HttpServerStub;
import org.springframework.cloud.contract.stubrunner.HttpServerStubConfiguration;
import org.springframework.cloud.contract.stubrunner.HttpServerStubConfigurer;
import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsEscapeHelper;
import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsJsonPathHelper;
import org.springframework.cloud.contract.verifier.dsl.wiremock.DefaultResponseTransformer;
import org.springframework.cloud.contract.verifier.dsl.wiremock.HandlebarsEscapeHelperExtension;
import org.springframework.cloud.contract.verifier.dsl.wiremock.HandlebarsJsonHelperExtension;
import org.springframework.cloud.contract.verifier.dsl.wiremock.SpringCloudContractRequestMatcher;
import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions;
import org.springframework.cloud.contract.wiremock.WireMockSpring;
Expand Down Expand Up @@ -95,19 +92,12 @@ private Extension[] responseTransformers() {
}
}
else {
extensions.addAll(Arrays.asList(new DefaultResponseTransformer(false, helpers()),
extensions.addAll(Arrays.asList(new HandlebarsEscapeHelperExtension(), new HandlebarsJsonHelperExtension(),
new SpringCloudContractRequestMatcher()));
}
return extensions.toArray(new Extension[extensions.size()]);
}

private Map<String, Helper<?>> helpers() {
Map<String, Helper<?>> helpers = new HashMap<>();
helpers.put(HandlebarsJsonPathHelper.NAME, new HandlebarsJsonPathHelper());
helpers.put(HandlebarsEscapeHelper.NAME, new HandlebarsEscapeHelper());
return helpers;
}

@Override
public int port() {
return isRunning() ? (this.https ? this.wireMockServer.httpsPort() : this.wireMockServer.port()) : INVALID_PORT;
Expand Down Expand Up @@ -212,7 +202,7 @@ private boolean validMapping(File file) {

StubMapping getMapping(File file) {
try (InputStream stream = Files.newInputStream(file.toPath())) {
return StubMapping.buildFrom(StreamUtils.copyToString(stream, Charset.forName("UTF-8")));
return StubMapping.buildFrom(StreamUtils.copyToString(stream, StandardCharsets.UTF_8));
}
catch (IOException | JsonException e) {
throw new IllegalStateException("Cannot read file", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ import com.github.tomakehurst.wiremock.common.FileSource
import com.github.tomakehurst.wiremock.extension.Extension
import com.github.tomakehurst.wiremock.extension.Parameters
import com.github.tomakehurst.wiremock.extension.ResponseTransformer
import com.github.tomakehurst.wiremock.http.ChunkedDribbleDelay
import com.github.tomakehurst.wiremock.http.HttpHeader
import com.github.tomakehurst.wiremock.http.HttpHeaders
import com.github.tomakehurst.wiremock.http.Request
import com.github.tomakehurst.wiremock.http.Response
import groovy.transform.CompileStatic

import org.springframework.cloud.contract.verifier.dsl.wiremock.DefaultResponseTransformer
import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensions

/**
Expand All @@ -37,7 +35,7 @@ import org.springframework.cloud.contract.verifier.dsl.wiremock.WireMockExtensio
class TestWireMockExtensions implements WireMockExtensions {
@Override
List<Extension> extensions() {
return [ new DefaultResponseTransformer(), new CustomExtension() ] as List<Extension>
return [new CustomExtension()] as List<Extension>
}
}

Expand All @@ -60,16 +58,16 @@ class CustomExtension extends ResponseTransformer {
Response transform(Request request, Response response, FileSource files, Parameters parameters) {
HttpHeaders headers = response.headers + new HttpHeader("X-My-Header", "surprise!")
return Response.response()
.status(response.status)
.statusMessage(response.statusMessage)
.body(response.body)
.headers(headers)
.configured(response.wasConfigured())
.fault(response.fault)
.incrementInitialDelay(response.initialDelay)
.chunkedDribbleDelay(response.chunkedDribbleDelay)
.fromProxy(response.fromProxy)
.build()
.status(response.status)
.statusMessage(response.statusMessage)
.body(response.body)
.headers(headers)
.configured(response.wasConfigured())
.fault(response.fault)
.incrementInitialDelay(response.initialDelay)
.chunkedDribbleDelay(response.chunkedDribbleDelay)
.fromProxy(response.fromProxy)
.build()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
<artifactId>groovy-nio</artifactId>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8-standalone</artifactId>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
8 changes: 6 additions & 2 deletions spring-cloud-contract-verifier/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8-standalone</artifactId>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
</dependency>
<dependency>
<groupId>com.toomuchcoding.jsonassert</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2013-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.contract.verifier.dsl.wiremock;

import java.util.Map;

import com.github.tomakehurst.wiremock.extension.TemplateHelperProviderExtension;
import wiremock.com.github.jknack.handlebars.Helper;

import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsEscapeHelper;

/**
* Template extension that register {@link HandlebarsEscapeHelper} in Wiremock.
* @author Kamil Dobrzynski
*/
public class HandlebarsEscapeHelperExtension implements TemplateHelperProviderExtension {

@Override
public Map<String, Helper<?>> provideTemplateHelpers() {
return Map.of(HandlebarsEscapeHelper.NAME, new HandlebarsEscapeHelper());
}

@Override
public String getName() {
return HandlebarsEscapeHelper.NAME;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2013-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.cloud.contract.verifier.dsl.wiremock;

import java.util.Map;

import com.github.tomakehurst.wiremock.extension.TemplateHelperProviderExtension;
import wiremock.com.github.jknack.handlebars.Helper;

import org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsJsonPathHelper;

/**
* Template extension that register {@link HandlebarsJsonPathHelper} in Wiremock.
* @author Kamil Dobrzynski
*/
public class HandlebarsJsonHelperExtension implements TemplateHelperProviderExtension {

@Override
public Map<String, Helper<?>> provideTemplateHelpers() {
return Map.of(HandlebarsJsonPathHelper.NAME, new HandlebarsJsonPathHelper());
}

@Override
public String getName() {
return HandlebarsJsonPathHelper.NAME;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Stream;

import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder;
import com.github.tomakehurst.wiremock.extension.Extension;
import com.github.tomakehurst.wiremock.extension.responsetemplating.ResponseTemplateTransformer;
import com.github.tomakehurst.wiremock.http.HttpHeader;
import com.github.tomakehurst.wiremock.http.HttpHeaders;
import com.github.tomakehurst.wiremock.http.ResponseDefinition;
Expand Down Expand Up @@ -83,10 +85,12 @@ private String[] responseTransformerNames() {
List<WireMockExtensions> wireMockExtensions = SpringFactoriesLoader.loadFactories(WireMockExtensions.class,
null);
if (!wireMockExtensions.isEmpty()) {
return wireMockExtensions.stream().map(WireMockExtensions::extensions).flatMap(Collection::stream)
.map(Extension::getName).toArray(String[]::new);
return Stream
.concat(Stream.of(ResponseTemplateTransformer.NAME), wireMockExtensions.stream()
.map(WireMockExtensions::extensions).flatMap(Collection::stream).map(Extension::getName))
.toArray(String[]::new);
}
return new String[] { new DefaultResponseTransformer().getName(), SpringCloudContractRequestMatcher.NAME };
return new String[] { ResponseTemplateTransformer.NAME, SpringCloudContractRequestMatcher.NAME };
}

private void appendHeaders(ResponseDefinitionBuilder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.concurrent.TimeUnit;

import javax.annotation.Nullable;
import jakarta.annotation.Nullable;

import org.springframework.cloud.contract.verifier.converter.YamlContract;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.Map;

import javax.annotation.Nullable;
import jakarta.annotation.Nullable;

import org.springframework.cloud.contract.verifier.converter.YamlContract;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

import java.util.Map;

import javax.annotation.Nullable;

import jakarta.annotation.Nullable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class TestWireMockExtensions implements WireMockExtensions {
@Override
List<Extension> extensions() {
return [
new DefaultResponseTransformer(),
new CustomExtension()
]
}
Expand Down
Loading
Loading