Updates version to 5.0.0-SNAPSHOT

Updates for framework 7
This commit is contained in:
spencergibb
2025-06-06 20:36:21 -04:00
parent 96f7167358
commit c09dc87020
54 changed files with 160 additions and 107 deletions

View File

@@ -76,7 +76,7 @@ public class ContractExchangeHandler extends WireMockVerifyHelper<EntityExchange
}
private void addResponseHeaders(ResponseDefinitionBuilder definition, HttpHeaders httpHeaders) {
for (String name : httpHeaders.keySet()) {
for (String name : httpHeaders.headerNames()) {
definition.withHeader(name, httpHeaders.get(name).toArray(new String[0]));
}
}
@@ -160,13 +160,13 @@ class WireMockHttpRequestAdapter implements Request {
@Override
public String getHeader(String key) {
HttpHeaders headers = this.result.getRequestHeaders();
return headers.containsKey(key) ? headers.getFirst(key) : null;
return headers.containsHeader(key) ? headers.getFirst(key) : null;
}
@Override
public HttpHeader header(String key) {
HttpHeaders headers = this.result.getRequestHeaders();
return headers.containsKey(key) ? new HttpHeader(key, headers.getValuesAsList(key)) : null;
return headers.containsHeader(key) ? new HttpHeader(key, headers.getValuesAsList(key)) : null;
}
@Override
@@ -182,7 +182,7 @@ class WireMockHttpRequestAdapter implements Request {
public com.github.tomakehurst.wiremock.http.HttpHeaders getHeaders() {
com.github.tomakehurst.wiremock.http.HttpHeaders target = new com.github.tomakehurst.wiremock.http.HttpHeaders();
HttpHeaders headers = this.result.getRequestHeaders();
for (String key : headers.keySet()) {
for (String key : headers.headerNames()) {
target = target.plus(new HttpHeader(key, headers.getValuesAsList(key)));
}
return target;
@@ -190,12 +190,12 @@ class WireMockHttpRequestAdapter implements Request {
@Override
public boolean containsHeader(String key) {
return this.result.getRequestHeaders().containsKey(key);
return this.result.getRequestHeaders().containsHeader(key);
}
@Override
public Set<String> getAllHeaderKeys() {
return this.result.getRequestHeaders().keySet();
return this.result.getRequestHeaders().headerNames();
}
@Override

View File

@@ -169,7 +169,7 @@ public class WireMockSnippet implements Snippet {
private MappingBuilder requestHeaders(MappingBuilder request, Operation operation) {
org.springframework.http.HttpHeaders headers = operation.getRequest().getHeaders();
// TODO: whitelist headers
for (String name : headers.keySet()) {
for (String name : headers.headerNames()) {
if (!this.headerBlackList.contains(name.toLowerCase(Locale.ROOT))) {
if ("content-type".equalsIgnoreCase(name) && this.contentType != null) {
continue;
@@ -239,7 +239,7 @@ public class WireMockSnippet implements Snippet {
private HttpHeaders responseHeaders(Operation operation) {
org.springframework.http.HttpHeaders headers = operation.getResponse().getHeaders();
HttpHeaders result = new HttpHeaders();
for (String name : headers.keySet()) {
for (String name : headers.headerNames()) {
if (!this.headerBlackList.contains(name.toLowerCase(Locale.ROOT))) {
result = result.plus(new HttpHeader(name, headers.get(name)));
}

View File

@@ -44,8 +44,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.ForwardedHeaderUtils;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import static org.hamcrest.CoreMatchers.containsString;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
@@ -123,7 +123,8 @@ public class WiremockServerRestDocsApplicationTests {
@ResponseBody
@RequestMapping("/link")
public String link(HttpServletRequest request) {
UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(request))
ServletServerHttpRequest req = new ServletServerHttpRequest(request);
UriComponents uriComponents = ForwardedHeaderUtils.adaptFromForwardedHeaders(req.getURI(), req.getHeaders())
.build();
return "link: " + uriComponents.toUriString();
}

View File

@@ -37,8 +37,8 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.ForwardedHeaderUtils;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import static org.hamcrest.CoreMatchers.containsString;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
@@ -75,7 +75,8 @@ public class WiremockServerRestDocsHypermediaApplicationTests {
@ResponseBody
@RequestMapping("/link")
public String resource(HttpServletRequest request) {
UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(request))
ServletServerHttpRequest req = new ServletServerHttpRequest(request);
UriComponents uriComponents = ForwardedHeaderUtils.adaptFromForwardedHeaders(req.getURI(), req.getHeaders())
.build();
return "link: " + uriComponents.toUriString();
}

View File

@@ -39,8 +39,8 @@ import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.ForwardedHeaderUtils;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import static org.hamcrest.CoreMatchers.containsString;
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;
@@ -106,7 +106,9 @@ public class WiremockServerWebTestClientApplicationTests {
@ResponseBody
@RequestMapping("/link")
public String link(ServerHttpRequest request) {
UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(request).build();
UriComponents uriComponents = ForwardedHeaderUtils
.adaptFromForwardedHeaders(request.getURI(), request.getHeaders())
.build();
return "link: " + uriComponents.toUriString();
}

View File

@@ -27,11 +27,9 @@ import org.apache.groovy.util.Maps;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.contract.spec.Contract;
import org.springframework.cloud.contract.spec.internal.Header;
import org.springframework.cloud.contract.spec.internal.QueryParameter;
@@ -39,8 +37,6 @@ import org.springframework.cloud.contract.verifier.util.ContractVerifierDslConve
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.restdocs.JUnitRestDocumentation;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@@ -61,14 +57,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
/**
* @author Marcin Grzejszczak
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ContractDslSnippetTests.Config.class)
// FIXME: 5.0.0 restdocs dropped junit 4
// @RunWith(SpringRunner.class)
// @SpringBootTest(classes = ContractDslSnippetTests.Config.class)
public class ContractDslSnippetTests {
private static final String OUTPUT = "target/generated-snippets";
@Rule
public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(OUTPUT);
// public JUnitRestDocumentation restDocumentation = new
// JUnitRestDocumentation(OUTPUT);
MockMvc mockMvc;
@@ -78,7 +76,7 @@ public class ContractDslSnippetTests {
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(documentationConfiguration(this.restDocumentation).snippets()
.apply(documentationConfiguration(null/* this.restDocumentation */).snippets()
.withAdditionalDefaults(new WireMockSnippet()))
.build();
}