Skip to content

Commit f82311f

Browse files
committed
FINERACT-2380: move retrofit client based test to feign
1 parent 9a16a26 commit f82311f

File tree

86 files changed

+4475
-4757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+4475
-4757
lines changed

.github/workflows/build-mariadb.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=5s --health-timeout=2s --health-retries=3
2626

2727
mock-oauth2-server:
28-
image: ghcr.io/navikt/mock-oauth2-server:3.0.1
28+
image: ghcr.io/navikt/mock-oauth2-server:2.1.10
2929
ports:
3030
- 9000:9000
3131
env:

.github/workflows/build-mysql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
2626

2727
mock-oauth2-server:
28-
image: ghcr.io/navikt/mock-oauth2-server:3.0.1
28+
image: ghcr.io/navikt/mock-oauth2-server:2.1.10
2929
ports:
3030
- 9000:9000
3131
env:

.github/workflows/build-postgresql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
options: --health-cmd="pg_isready -q -d postgres -U root" --health-interval=5s --health-timeout=2s --health-retries=3
2727

2828
mock-oauth2-server:
29-
image: ghcr.io/navikt/mock-oauth2-server:3.0.1
29+
image: ghcr.io/navikt/mock-oauth2-server:2.1.10
3030
ports:
3131
- 9000:9000
3232
env:

.github/workflows/run-integration-test-sequentially-postgresql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
POSTGRES_PASSWORD: postgres
2323
options: --health-cmd="pg_isready -q -d postgres -U root" --health-interval=5s --health-timeout=2s --health-retries=3
2424
mock-oauth2-server:
25-
image: ghcr.io/navikt/mock-oauth2-server:3.0.1
25+
image: ghcr.io/navikt/mock-oauth2-server:2.1.10
2626
ports:
2727
- 9000:9000
2828
env:

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
timeout-minutes: 60
1717
steps:
18-
- uses: actions/stale@5f858e3efba33a5ca4407a664cc011ad407f2008 # v10
18+
- uses: actions/stale@5f858e3efba33a5ca4407a664cc011ad407f2008 # v9
1919
with:
2020
repo-token: ${{ secrets.GITHUB_TOKEN }}
2121
# stale-issue-message: 'Stale issue message'

fineract-client-feign/src/main/java/org/apache/fineract/client/feign/FineractFeignClient.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.apache.fineract.client.feign.services.EntityFieldConfigurationApi;
6262
import org.apache.fineract.client.feign.services.ExternalAssetOwnerLoanProductAttributesApi;
6363
import org.apache.fineract.client.feign.services.ExternalAssetOwnersApi;
64+
import org.apache.fineract.client.feign.services.ExternalAssetOwnersApiExtension;
6465
import org.apache.fineract.client.feign.services.ExternalEventConfigurationApi;
6566
import org.apache.fineract.client.feign.services.ExternalServicesApi;
6667
import org.apache.fineract.client.feign.services.FetchAuthenticatedUserDetailsApi;
@@ -95,10 +96,13 @@
9596
import org.apache.fineract.client.feign.services.LoanCollateralApi;
9697
import org.apache.fineract.client.feign.services.LoanCollateralManagementApi;
9798
import org.apache.fineract.client.feign.services.LoanDisbursementDetailsApi;
99+
import org.apache.fineract.client.feign.services.LoanDisbursementDetailsApiExtension;
98100
import org.apache.fineract.client.feign.services.LoanInterestPauseApi;
99101
import org.apache.fineract.client.feign.services.LoanProductsApi;
102+
import org.apache.fineract.client.feign.services.LoanProductsApiExtension;
100103
import org.apache.fineract.client.feign.services.LoanReschedulingApi;
101104
import org.apache.fineract.client.feign.services.LoanTransactionsApi;
105+
import org.apache.fineract.client.feign.services.LoanTransactionsApiExtension;
102106
import org.apache.fineract.client.feign.services.LoansApi;
103107
import org.apache.fineract.client.feign.services.LoansPointInTimeApi;
104108
import org.apache.fineract.client.feign.services.MakerCheckerOr4EyeFunctionalityApi;
@@ -392,6 +396,10 @@ public ExternalAssetOwnersApi externalAssetOwners() {
392396
return create(ExternalAssetOwnersApi.class);
393397
}
394398

399+
public ExternalAssetOwnersApiExtension externalAssetOwnersExtension() {
400+
return create(ExternalAssetOwnersApiExtension.class);
401+
}
402+
395403
public ExternalEventConfigurationApi externalEventConfiguration() {
396404
return create(ExternalEventConfigurationApi.class);
397405
}
@@ -528,6 +536,10 @@ public LoanDisbursementDetailsApi loanDisbursementDetails() {
528536
return create(LoanDisbursementDetailsApi.class);
529537
}
530538

539+
public LoanDisbursementDetailsApiExtension loanDisbursementDetailsExtension() {
540+
return create(LoanDisbursementDetailsApiExtension.class);
541+
}
542+
531543
public LoanInterestPauseApi loanInterestPause() {
532544
return create(LoanInterestPauseApi.class);
533545
}
@@ -536,6 +548,10 @@ public LoanProductsApi loanProducts() {
536548
return create(LoanProductsApi.class);
537549
}
538550

551+
public LoanProductsApiExtension loanProductsExtension() {
552+
return create(LoanProductsApiExtension.class);
553+
}
554+
539555
public LoanReschedulingApi loanRescheduling() {
540556
return create(LoanReschedulingApi.class);
541557
}
@@ -544,6 +560,10 @@ public LoanTransactionsApi loanTransactions() {
544560
return create(LoanTransactionsApi.class);
545561
}
546562

563+
public LoanTransactionsApiExtension loanTransactionsExtension() {
564+
return create(LoanTransactionsApiExtension.class);
565+
}
566+
547567
public LoansApi loans() {
548568
return create(LoansApi.class);
549569
}

fineract-client-feign/src/main/java/org/apache/fineract/client/feign/FineractFeignClientConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
4242
import org.apache.hc.core5.util.TimeValue;
4343
import org.apache.hc.core5.util.Timeout;
44+
import org.apache.fineract.client.feign.support.HeaderCapturingDecoder;
4445

4546
/**
4647
* Configuration class for Feign client.
@@ -95,7 +96,8 @@ public <T> T createClient(Class<T> apiType) {
9596
Encoder multipartEncoder = new FineractMultipartEncoder(jacksonEncoder);
9697

9798
return Feign.builder().client(getOrCreateHttpClient()).encoder(multipartEncoder)
98-
.decoder(new JacksonDecoder(ObjectMapperFactory.getShared())).errorDecoder(new FineractErrorDecoder())
99+
.decoder(new HeaderCapturingDecoder(new JacksonDecoder(ObjectMapperFactory.getShared())))
100+
.errorDecoder(new FineractErrorDecoder())
99101
.options(new Request.Options(connectTimeout, TimeUnit.MILLISECONDS, readTimeout, TimeUnit.MILLISECONDS, true))
100102
.retryer(Retryer.NEVER_RETRY).requestInterceptor(new BasicAuthRequestInterceptor(username, password))
101103
.requestInterceptor(new TenantIdRequestInterceptor(tenantId)).logger(new Slf4jLogger(apiType))

fineract-client-feign/src/main/java/org/apache/fineract/client/feign/util/CallFailedRuntimeException.java

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@
1818
*/
1919
package org.apache.fineract.client.feign.util;
2020

21-
import com.fasterxml.jackson.databind.JsonNode;
22-
import com.fasterxml.jackson.databind.ObjectMapper;
23-
import feign.FeignException;
24-
import java.io.IOException;
25-
import java.nio.charset.StandardCharsets;
2621
import lombok.Getter;
2722
import lombok.extern.slf4j.Slf4j;
23+
import org.apache.fineract.client.feign.FeignException;
2824

2925
/**
3026
* Exception thrown by {@link FeignCalls} utility when Feign calls fail.
@@ -49,7 +45,7 @@ private static String createMessage(FeignException e) {
4945
sb.append(", request=").append(e.request().url());
5046
}
5147

52-
String contentString = e.contentUTF8();
48+
String contentString = e.responseBodyAsString();
5349
if (contentString != null && !contentString.isEmpty()) {
5450
sb.append(", errorBody=").append(contentString);
5551
}
@@ -58,34 +54,9 @@ private static String createMessage(FeignException e) {
5854
}
5955

6056
private static String extractDeveloperMessage(FeignException e) {
61-
try {
62-
byte[] content = e.content();
63-
if (content == null || content.length == 0) {
64-
return e.getMessage();
65-
}
66-
67-
String contentString = new String(content, StandardCharsets.UTF_8);
68-
ObjectMapper mapper = new ObjectMapper();
69-
JsonNode root = mapper.readTree(contentString);
70-
71-
if (root.has("developerMessage")) {
72-
return root.get("developerMessage").asText();
73-
}
74-
75-
if (root.has("errors")) {
76-
JsonNode errors = root.get("errors");
77-
if (errors.isArray() && errors.size() > 0) {
78-
JsonNode firstError = errors.get(0);
79-
if (firstError.has("developerMessage")) {
80-
return firstError.get("developerMessage").asText();
81-
}
82-
}
83-
}
84-
85-
return contentString;
86-
} catch (IOException ex) {
87-
log.warn("Failed to extract developer message from error response", ex);
88-
return e.getMessage();
57+
if (e.getDeveloperMessage() != null) {
58+
return e.getDeveloperMessage();
8959
}
60+
return e.getMessage();
9061
}
9162
}

fineract-client-feign/src/main/java/org/apache/fineract/client/feign/util/FeignCalls.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
*/
1919
package org.apache.fineract.client.feign.util;
2020

21-
import feign.FeignException;
2221
import java.util.function.Supplier;
22+
import org.apache.fineract.client.feign.FeignException;
2323

2424
/**
2525
* Extension methods for Feign calls. This class is recommended to be statically imported.
@@ -77,4 +77,41 @@ public static void executeVoid(Runnable feignCall) throws CallFailedRuntimeExcep
7777
public static <T> T execute(Supplier<T> feignCall) throws FeignException {
7878
return feignCall.get();
7979
}
80+
81+
/**
82+
* Execute a Feign call expecting failure (for negative tests). Returns the exception with error details.
83+
*
84+
* @param feignCall
85+
* the Feign call to execute
86+
* @return CallFailedRuntimeException containing status code and error message
87+
* @throws AssertionError
88+
* if the call succeeds when failure was expected
89+
*/
90+
public static CallFailedRuntimeException fail(Supplier<?> feignCall) {
91+
try {
92+
Object result = feignCall.get();
93+
throw new AssertionError("Expected call to fail, but it succeeded with result: " + result);
94+
} catch (FeignException e) {
95+
return new CallFailedRuntimeException(e);
96+
}
97+
}
98+
99+
/**
100+
* Execute a Feign call expecting failure with void return (for negative tests). Returns the exception with error
101+
* details.
102+
*
103+
* @param feignCall
104+
* the Feign call to execute
105+
* @return CallFailedRuntimeException containing status code and error message
106+
* @throws AssertionError
107+
* if the call succeeds when failure was expected
108+
*/
109+
public static CallFailedRuntimeException failVoid(Runnable feignCall) {
110+
try {
111+
feignCall.run();
112+
throw new AssertionError("Expected call to fail, but it succeeded");
113+
} catch (FeignException e) {
114+
return new CallFailedRuntimeException(e);
115+
}
116+
}
80117
}

fineract-core/src/main/java/org/apache/fineract/infrastructure/event/external/jobs/SendAsynchronousEventsTasklet.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,24 @@ public class SendAsynchronousEventsTasklet implements Tasklet {
7575
@Override
7676
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
7777
try {
78-
if (isDownstreamChannelEnabled()) {
78+
boolean isEnabled = isDownstreamChannelEnabled();
79+
log.info("DEBUG: isDownstreamChannelEnabled={}, jms.enabled={}, kafka.enabled={}", isEnabled,
80+
fineractProperties.getEvents().getExternal().getProducer().getJms().isEnabled(),
81+
fineractProperties.getEvents().getExternal().getProducer().getKafka().isEnabled());
82+
if (isEnabled) {
7983
List<ExternalEventView> events = getQueuedEventsBatch();
8084
log.debug("Queued events size: {}", events.size());
8185
sendEvents(events);
86+
} else {
87+
log.info("DEBUG: Downstream channel is DISABLED - skipping event sending");
8288
}
8389
} catch (Exception e) {
8490
log.error("Error occurred while processing events: ", e);
8591
}
8692
return RepeatStatus.FINISHED;
8793
}
8894

89-
protected boolean isDownstreamChannelEnabled() {
95+
private boolean isDownstreamChannelEnabled() {
9096
return fineractProperties.getEvents().getExternal().getProducer().getJms().isEnabled()
9197
|| fineractProperties.getEvents().getExternal().getProducer().getKafka().isEnabled();
9298
}

0 commit comments

Comments
 (0)