FINERACT-2346: Refractor, Minor Sonar fixes and remove some deprecated code

This commit is contained in:
Aman-Mittal
2025-12-01 19:11:59 +01:00
committed by Adam Saghy
parent 73d8659390
commit 00e9ac8320
17 changed files with 83 additions and 123 deletions
@@ -24,6 +24,9 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.common.ContentTypes.APPLICATION_JSON;
import static com.github.tomakehurst.wiremock.common.ContentTypes.AUTHORIZATION;
import static com.github.tomakehurst.wiremock.common.ContentTypes.CONTENT_TYPE;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -66,9 +69,8 @@ class FineractFeignClientIntegrationTest {
@Test
void testJsonEncoding() {
wireMockServer
.stubFor(post(urlEqualTo("/test")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")
.withBody("{\"id\":1,\"message\":\"success\",\"timestamp\":\"2024-01-15T10:30:00\"}")));
wireMockServer.stubFor(post(urlEqualTo("/test")).willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, APPLICATION_JSON)
.withBody("{\"id\":1,\"message\":\"success\",\"timestamp\":\"2024-01-15T10:30:00\"}")));
TestApi client = config.createClient(TestApi.class);
TestRequest request = new TestRequest();
@@ -85,9 +87,8 @@ class FineractFeignClientIntegrationTest {
@Test
void testJsonDecoding() {
wireMockServer
.stubFor(get(urlEqualTo("/test")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")
.withBody("{\"id\":42,\"message\":\"decoded-message\",\"timestamp\":\"2024-12-25T18:45:30\"}")));
wireMockServer.stubFor(get(urlEqualTo("/test")).willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, APPLICATION_JSON)
.withBody("{\"id\":42,\"message\":\"decoded-message\",\"timestamp\":\"2024-12-25T18:45:30\"}")));
TestApi client = config.createClient(TestApi.class);
TestResponse response = client.getTest();
@@ -101,7 +102,7 @@ class FineractFeignClientIntegrationTest {
@Test
void testJava8DateTimeSerialization() {
wireMockServer.stubFor(post(urlEqualTo("/test")).withRequestBody(containing("2024-06-30"))
.willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")
.willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, APPLICATION_JSON)
.withBody("{\"id\":99,\"message\":\"date-test\",\"timestamp\":\"2024-06-30T12:00:00\"}")));
TestApi client = config.createClient(TestApi.class);
@@ -131,7 +132,7 @@ class FineractFeignClientIntegrationTest {
@Test
void testErrorDecoderWithServerError() {
wireMockServer.stubFor(
get(urlEqualTo("/error")).willReturn(aResponse().withStatus(500).withHeader("Content-Type", "application/json").withBody(
get(urlEqualTo("/error")).willReturn(aResponse().withStatus(500).withHeader(CONTENT_TYPE, APPLICATION_JSON).withBody(
"{\"developerMessage\":\"Internal server error occurred\",\"httpStatusCode\":\"500\",\"defaultUserMessage\":\"Server Error\"}")));
TestApi client = config.createClient(TestApi.class);
@@ -144,9 +145,8 @@ class FineractFeignClientIntegrationTest {
FineractFeignClientConfig ttlConfig = FineractFeignClientConfig.builder().baseUrl(baseUrl).credentials("testuser", "testpass")
.connectionTimeToLive(5, TimeUnit.MINUTES).build();
wireMockServer
.stubFor(get(urlEqualTo("/test")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")
.withBody("{\"id\":1,\"message\":\"ttl-test\",\"timestamp\":\"2024-01-01T00:00:00\"}")));
wireMockServer.stubFor(get(urlEqualTo("/test")).willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, APPLICATION_JSON)
.withBody("{\"id\":1,\"message\":\"ttl-test\",\"timestamp\":\"2024-01-01T00:00:00\"}")));
TestApi client = ttlConfig.createClient(TestApi.class);
TestResponse response = client.getTest();
@@ -157,8 +157,8 @@ class FineractFeignClientIntegrationTest {
@Test
void testBasicAuthentication() {
wireMockServer.stubFor(get(urlEqualTo("/test")).withHeader("Authorization", equalTo("Basic dGVzdHVzZXI6dGVzdHBhc3M="))
.willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")
wireMockServer.stubFor(get(urlEqualTo("/test")).withHeader(AUTHORIZATION, equalTo("Basic dGVzdHVzZXI6dGVzdHBhc3M="))
.willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, APPLICATION_JSON)
.withBody("{\"id\":1,\"message\":\"authenticated\",\"timestamp\":\"2024-01-01T00:00:00\"}")));
TestApi client = config.createClient(TestApi.class);
@@ -170,9 +170,8 @@ class FineractFeignClientIntegrationTest {
@Test
void testNullValueHandling() {
wireMockServer
.stubFor(post(urlEqualTo("/test")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")
.withBody("{\"id\":1,\"message\":null,\"timestamp\":\"2024-01-01T00:00:00\"}")));
wireMockServer.stubFor(post(urlEqualTo("/test")).willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, APPLICATION_JSON)
.withBody("{\"id\":1,\"message\":null,\"timestamp\":\"2024-01-01T00:00:00\"}")));
TestApi client = config.createClient(TestApi.class);
TestRequest request = new TestRequest();
@@ -24,6 +24,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
import static com.github.tomakehurst.wiremock.common.ContentTypes.CONTENT_TYPE;
import static org.assertj.core.api.Assertions.assertThat;
import com.github.tomakehurst.wiremock.WireMockServer;
@@ -75,14 +76,14 @@ class ImagesApiIntegrationTest {
void testRetrieveClientImage() throws IOException {
byte[] imageData = new byte[] { (byte) 0xFF, (byte) 0xD8, (byte) 0xFF, 0x10, 0x11, 0x12 };
wireMockServer.stubFor(get(urlEqualTo("/v1/clients/123/images"))
.willReturn(aResponse().withStatus(200).withHeader("Content-Type", "image/jpeg").withBody(imageData)));
.willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, "image/jpeg").withBody(imageData)));
ImagesApi api = config.createClient(ImagesApi.class);
Response response = api.get("clients", 123L, new HashMap<>());
assertThat(response.status()).isEqualTo(200);
assertThat(response.headers()).containsKey("Content-Type");
assertThat(response.headers().get("Content-Type")).contains("image/jpeg");
assertThat(response.headers()).containsKey(CONTENT_TYPE);
assertThat(response.headers().get(CONTENT_TYPE)).contains("image/jpeg");
assertThat(response.body().asInputStream().readAllBytes()).isEqualTo(imageData);
}
@@ -91,7 +92,7 @@ class ImagesApiIntegrationTest {
byte[] resizedImage = new byte[] { (byte) 0xFF, (byte) 0xD8, (byte) 0xFF, 0x20, 0x21 };
wireMockServer.stubFor(get(urlPathEqualTo("/v1/clients/123/images")).withQueryParam("maxWidth", equalTo("100"))
.withQueryParam("maxHeight", equalTo("100"))
.willReturn(aResponse().withStatus(200).withHeader("Content-Type", "image/jpeg").withBody(resizedImage)));
.willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, "image/jpeg").withBody(resizedImage)));
ImagesApi api = config.createClient(ImagesApi.class);
Map<String, Object> params = new HashMap<>();
@@ -108,7 +109,7 @@ class ImagesApiIntegrationTest {
void testRetrieveClientImageWithMaxWidthOnly() throws IOException {
byte[] resizedImage = new byte[] { (byte) 0xFF, (byte) 0xD8, (byte) 0xFF, 0x30 };
wireMockServer.stubFor(get(urlPathEqualTo("/v1/clients/123/images")).withQueryParam("maxWidth", equalTo("200"))
.willReturn(aResponse().withStatus(200).withHeader("Content-Type", "image/jpeg").withBody(resizedImage)));
.willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, "image/jpeg").withBody(resizedImage)));
ImagesApi api = config.createClient(ImagesApi.class);
Map<String, Object> params = new HashMap<>();
@@ -123,7 +124,7 @@ class ImagesApiIntegrationTest {
@Test
void testDeleteClientImage() {
wireMockServer.stubFor(delete(urlEqualTo("/v1/clients/123/images"))
.willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody("{\"resourceId\":123}")));
.willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, "application/json").withBody("{\"resourceId\":123}")));
ImagesApi api = config.createClient(ImagesApi.class);
Response response = api.delete("clients", 123L);
@@ -134,7 +135,7 @@ class ImagesApiIntegrationTest {
@Test
void testDeleteStaffImage() {
wireMockServer.stubFor(delete(urlEqualTo("/v1/staff/456/images"))
.willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json").withBody("{\"resourceId\":456}")));
.willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, "application/json").withBody("{\"resourceId\":456}")));
ImagesApi api = config.createClient(ImagesApi.class);
Response response = api.delete("staff", 456L);
@@ -146,13 +147,13 @@ class ImagesApiIntegrationTest {
void testRetrieveImageWithPngFormat() throws IOException {
byte[] pngImage = new byte[] { (byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A };
wireMockServer.stubFor(get(urlEqualTo("/v1/clients/123/images"))
.willReturn(aResponse().withStatus(200).withHeader("Content-Type", "image/png").withBody(pngImage)));
.willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, "image/png").withBody(pngImage)));
ImagesApi api = config.createClient(ImagesApi.class);
Response response = api.get("clients", 123L, new HashMap<>());
assertThat(response.status()).isEqualTo(200);
assertThat(response.headers().get("Content-Type")).contains("image/png");
assertThat(response.headers().get(CONTENT_TYPE)).contains("image/png");
assertThat(response.body().asInputStream().readAllBytes()).isEqualTo(pngImage);
}
@@ -166,7 +167,7 @@ class ImagesApiIntegrationTest {
Long entityId = entityIds[i];
wireMockServer.stubFor(get(urlEqualTo("/v1/" + entityType + "/" + entityId + "/images"))
.willReturn(aResponse().withStatus(200).withHeader("Content-Type", "image/jpeg").withBody(new byte[] { 0x01 })));
.willReturn(aResponse().withStatus(200).withHeader(CONTENT_TYPE, "image/jpeg").withBody(new byte[] { 0x01 })));
}
ImagesApi api = config.createClient(ImagesApi.class);