Upgrade to HttpClient5 5.2.1

Closes gh-34086
This commit is contained in:
Andy Wilkinson
2023-02-06 13:18:24 +00:00
parent 850d239b5c
commit f595b46bd3
8 changed files with 38 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@@ -38,6 +38,7 @@ import org.springframework.util.StreamUtils;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -70,7 +71,7 @@ public abstract class AbstractHttpClientMockTests {
byte[] content = readClasspathResource(contentPath);
mockHttpEntity(response, content, contentType);
mockStatus(response, 200);
given(this.http.execute(any(HttpHost.class), argThat(getForMetadata(serviceCapabilities))))
given(this.http.executeOpen(any(HttpHost.class), argThat(getForMetadata(serviceCapabilities)), isNull()))
.willReturn(response);
}
@@ -87,7 +88,7 @@ public abstract class AbstractHttpClientMockTests {
mockStatus(response, 200);
String header = (request.fileName != null) ? contentDispositionValue(request.fileName) : null;
mockHttpHeader(response, "Content-Disposition", header);
given(this.http.execute(any(HttpHost.class), argThat(getForNonMetadata()))).willReturn(response);
given(this.http.executeOpen(any(HttpHost.class), argThat(getForNonMetadata()), isNull())).willReturn(response);
}
protected void mockProjectGenerationError(int status, String message) throws IOException, JSONException {
@@ -96,14 +97,14 @@ public abstract class AbstractHttpClientMockTests {
ClassicHttpResponse response = mock(ClassicHttpResponse.class);
mockHttpEntity(response, createJsonError(status, message).getBytes(), "application/json");
mockStatus(response, status);
given(this.http.execute(any(HttpHost.class), isA(HttpGet.class))).willReturn(response);
given(this.http.executeOpen(any(HttpHost.class), isA(HttpGet.class), isNull())).willReturn(response);
}
protected void mockMetadataGetError(int status, String message) throws IOException, JSONException {
ClassicHttpResponse response = mock(ClassicHttpResponse.class);
mockHttpEntity(response, createJsonError(status, message).getBytes(), "application/json");
mockStatus(response, status);
given(this.http.execute(any(HttpHost.class), isA(HttpGet.class))).willReturn(response);
given(this.http.executeOpen(any(HttpHost.class), isA(HttpGet.class), isNull())).willReturn(response);
}
protected HttpEntity mockHttpEntity(ClassicHttpResponse response, byte[] content, String contentType) {

View File

@@ -40,6 +40,7 @@ import org.springframework.boot.cli.command.status.ExitStatus;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.then;
/**
@@ -399,7 +400,7 @@ class InitCommandTests extends AbstractHttpClientMockTests {
@Test
void userAgent() throws Exception {
this.command.run("--list", "--target=https://fake-service");
then(this.http).should().execute(any(HttpHost.class), this.requestCaptor.capture());
then(this.http).should().executeOpen(any(HttpHost.class), this.requestCaptor.capture(), isNull());
Header agent = this.requestCaptor.getValue().getHeaders("User-Agent")[0];
assertThat(agent.getValue()).startsWith("SpringBootCli/");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@@ -25,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -95,7 +96,7 @@ class InitializrServiceTests extends AbstractHttpClientMockTests {
mockSuccessfulMetadataGet(false);
ClassicHttpResponse response = mock(ClassicHttpResponse.class);
mockStatus(response, 500);
given(this.http.execute(any(HttpHost.class), isA(HttpGet.class))).willReturn(response);
given(this.http.executeOpen(any(HttpHost.class), isA(HttpGet.class), isNull())).willReturn(response);
ProjectGenerationRequest request = new ProjectGenerationRequest();
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
.withMessageContaining("No content received from server");
@@ -115,7 +116,7 @@ class InitializrServiceTests extends AbstractHttpClientMockTests {
ClassicHttpResponse response = mock(ClassicHttpResponse.class);
mockHttpEntity(response, "Foo-Bar-Not-JSON".getBytes(), "application/json");
mockStatus(response, 200);
given(this.http.execute(any(HttpHost.class), isA(HttpGet.class))).willReturn(response);
given(this.http.executeOpen(any(HttpHost.class), isA(HttpGet.class), isNull())).willReturn(response);
ProjectGenerationRequest request = new ProjectGenerationRequest();
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
.withMessageContaining("Invalid content received from server");
@@ -125,7 +126,7 @@ class InitializrServiceTests extends AbstractHttpClientMockTests {
void loadMetadataNoContent() throws Exception {
ClassicHttpResponse response = mock(ClassicHttpResponse.class);
mockStatus(response, 500);
given(this.http.execute(any(HttpHost.class), isA(HttpGet.class))).willReturn(response);
given(this.http.executeOpen(any(HttpHost.class), isA(HttpGet.class), isNull())).willReturn(response);
ProjectGenerationRequest request = new ProjectGenerationRequest();
assertThatExceptionOfType(ReportableException.class).isThrownBy(() -> this.invoker.generate(request))
.withMessageContaining("No content received from server");