Adjust to changes in Framework.

This commit is contained in:
Olga Maciaszek-Sharma
2024-08-05 16:36:38 +02:00
parent 9b56a8bcba
commit a186766866
2 changed files with 14 additions and 11 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2024 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.
@@ -21,13 +21,14 @@ import java.io.IOException;
import java.io.InputStream;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.AbstractClientHttpResponse;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.client.ClientHttpResponse;
/**
* {@link RetryableStatusCodeException} that captures a {@link ClientHttpResponse}.
*
* @author Ryan Baxter
* @author Olga Maciaszek-Sharma
*/
public class ClientHttpResponseStatusCodeException extends RetryableStatusCodeException {
@@ -52,7 +53,7 @@ public class ClientHttpResponseStatusCodeException extends RetryableStatusCodeEx
return this.response;
}
static class ClientHttpResponseWrapper extends AbstractClientHttpResponse {
static class ClientHttpResponseWrapper implements ClientHttpResponse {
private ClientHttpResponse response;
@@ -64,8 +65,8 @@ public class ClientHttpResponseStatusCodeException extends RetryableStatusCodeEx
}
@Override
public int getRawStatusCode() throws IOException {
return this.response.getStatusCode().value();
public HttpStatusCode getStatusCode() throws IOException {
return this.response.getStatusCode();
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2024 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,7 +25,8 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.AbstractClientHttpResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.util.StreamUtils;
@@ -33,6 +34,7 @@ import static org.assertj.core.api.BDDAssertions.then;
/**
* @author Ryan Baxter
* @author Olga Maciaszek-Sharma
*/
@ExtendWith(MockitoExtension.class)
public class ClientHttpResponseStatusCodeExceptionTest {
@@ -44,19 +46,19 @@ public class ClientHttpResponseStatusCodeExceptionTest {
ClientHttpResponseStatusCodeException exp = new ClientHttpResponseStatusCodeException("service", response,
response.getStatusText().getBytes());
ClientHttpResponse expResponse = exp.getResponse();
then(expResponse.getStatusCode().value()).isEqualTo(response.getRawStatusCode());
then(expResponse.getStatusCode()).isEqualTo(response.getStatusCode());
then(expResponse.getStatusText()).isEqualTo(response.getStatusText());
then(expResponse.getHeaders()).isEqualTo(response.getHeaders());
then(new String(StreamUtils.copyToByteArray(expResponse.getBody()))).isEqualTo(response.getStatusText());
}
static class MyClientHttpResponse extends AbstractClientHttpResponse {
static class MyClientHttpResponse implements ClientHttpResponse {
private boolean closed = false;
@Override
public int getRawStatusCode() {
return 200;
public HttpStatusCode getStatusCode() {
return HttpStatus.OK;
}
@Override