Skip to content

Commit 297fa8e

Browse files
adamsaghygalovics
authored andcommitted
FINERACT-2326: Close opened savings account after integration test execution
1 parent 963f855 commit 297fa8e

26 files changed

+304
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.portfolio.savings.api;
20+
21+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
22+
import jakarta.ws.rs.Consumes;
23+
import jakarta.ws.rs.GET;
24+
import jakarta.ws.rs.Path;
25+
import jakarta.ws.rs.PathParam;
26+
import jakarta.ws.rs.Produces;
27+
import jakarta.ws.rs.core.Context;
28+
import jakarta.ws.rs.core.MediaType;
29+
import jakarta.ws.rs.core.UriInfo;
30+
import java.util.List;
31+
import lombok.RequiredArgsConstructor;
32+
import lombok.extern.slf4j.Slf4j;
33+
import org.apache.fineract.infrastructure.core.boot.FineractProfiles;
34+
import org.apache.fineract.portfolio.savings.domain.SavingsAccountRepository;
35+
import org.apache.fineract.portfolio.savings.service.SavingsAccountWritePlatformService;
36+
import org.springframework.beans.factory.InitializingBean;
37+
import org.springframework.context.annotation.Profile;
38+
import org.springframework.stereotype.Component;
39+
40+
@Profile(FineractProfiles.TEST)
41+
@Component
42+
@Path("/v1/internal/savingsaccounts")
43+
@RequiredArgsConstructor
44+
@Slf4j
45+
public class InternalSavingsAccountInformationApiResource implements InitializingBean {
46+
47+
private final SavingsAccountRepository repository;
48+
private final SavingsAccountWritePlatformService writePlatformService;
49+
50+
@Override
51+
@SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
52+
public void afterPropertiesSet() {
53+
log.warn("------------------------------------------------------------");
54+
log.warn(" ");
55+
log.warn("DO NOT USE THIS IN PRODUCTION!");
56+
log.warn("Internal savings account services mode is enabled");
57+
log.warn("DO NOT USE THIS IN PRODUCTION!");
58+
log.warn(" ");
59+
log.warn("------------------------------------------------------------");
60+
61+
}
62+
63+
@GET
64+
@Path("status/{statusId}")
65+
@Consumes({ MediaType.APPLICATION_JSON })
66+
@Produces({ MediaType.APPLICATION_JSON })
67+
@SuppressFBWarnings("SLF4J_SIGN_ONLY_FORMAT")
68+
public List<Long> getSavingsAccountsByStatus(@Context final UriInfo uriInfo, @PathParam("statusId") Integer statusId) {
69+
log.warn("------------------------------------------------------------");
70+
log.warn(" ");
71+
log.warn("Fetching loans by status {}", statusId);
72+
log.warn(" ");
73+
log.warn("------------------------------------------------------------");
74+
75+
return repository.findSavingsAccountIdsByStatusId(statusId);
76+
}
77+
}

fineract-provider/src/main/java/org/apache/fineract/portfolio/savings/api/SavingsAccountsApiResourceSwagger.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ private PostSavingsAccountsAccountIdRequest() {}
342342
public String approvedOnDate;
343343
@Schema(example = "05 September 2014")
344344
public String activatedOnDate;
345+
@Schema(example = "05 September 2014")
346+
public String closedOnDate;
347+
@Schema(example = "false")
348+
public Boolean withdrawBalance;
345349
}
346350

347351
@Schema(description = "PostSavingsAccountsAccountIdResponse")

fineract-savings/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepository.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,7 @@ SavingsAccount findByIdAndDepositAccountType(@Param("accountId") Long accountId,
9494
""")
9595
List<SavingsAccrualData> findAccrualData(@Param("tillDate") LocalDate tillDate, @Param("savingsId") Long savingsId,
9696
@Param("status") Integer status, @Param("accountingRule") Integer accountingRule);
97+
98+
@Query("SELECT sa.id FROM SavingsAccount sa WHERE sa.status = :status")
99+
List<Long> findSavingsAccountIdsByStatusId(Integer status);
97100
}

fineract-savings/src/main/java/org/apache/fineract/portfolio/savings/domain/SavingsAccountRepositoryWrapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,8 @@ public List<SavingsAccrualData> findAccrualData(final LocalDate tillDate, final
186186
final Integer accountingRule) {
187187
return this.repository.findAccrualData(tillDate, savingsId, status, accountingRule);
188188
}
189+
190+
public List<Long> findLoanIdsByStatusId(Integer status) {
191+
return null;
192+
}
189193
}

integration-tests/src/test/java/org/apache/fineract/integrationtests/BatchApiTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.apache.fineract.integrationtests;
2020

21-
import static java.lang.Integer.parseInt;
2221
import static org.apache.http.HttpStatus.SC_FORBIDDEN;
2322
import static org.hamcrest.Matchers.containsString;
2423
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -2459,7 +2458,7 @@ public void shoulRetrieveTheProperErrorDuringLockedLoan_OldRelativePath() {
24592458
ResponseSpecification conflictResponseSpec = new ResponseSpecBuilder().expectStatusCode(409).build();
24602459
ErrorResponse errorResponse = BatchHelper.postBatchRequestsWithoutEnclosingTransactionError(requestSpec, conflictResponseSpec,
24612460
jsonifiedRepaymentRequest);
2462-
assertEquals(409, parseInt(errorResponse.getHttpStatusCode()));
2461+
assertEquals(409, errorResponse.getHttpStatusCode());
24632462
}
24642463

24652464
/**
@@ -2541,7 +2540,7 @@ public void shoulRetrieveTheProperErrorDuringLockedLoan() {
25412540
ResponseSpecification conflictResponseSpec = new ResponseSpecBuilder().expectStatusCode(409).build();
25422541
ErrorResponse errorResponse = BatchHelper.postBatchRequestsWithoutEnclosingTransactionError(requestSpec, conflictResponseSpec,
25432542
jsonifiedRepaymentRequest);
2544-
assertEquals(409, parseInt(errorResponse.getHttpStatusCode()));
2543+
assertEquals(409, errorResponse.getHttpStatusCode());
25452544
}
25462545

25472546
@Test

integration-tests/src/test/java/org/apache/fineract/integrationtests/BatchLoanIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void test_InlineLoanCOB_ShouldExecute_WhenLoanIsHardLocked_And_Reschedule
157157
.approveRescheduleLoan(2L, 1L, "01 January 2023") //
158158
.executeEnclosingTransactionError(new ResponseSpecBuilder().expectStatusCode(409).build()); //
159159

160-
Assertions.assertEquals(HttpStatus.SC_CONFLICT, Integer.parseInt(response.getHttpStatusCode()));
160+
Assertions.assertEquals(HttpStatus.SC_CONFLICT, response.getHttpStatusCode());
161161
});
162162
});
163163
}

integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientSavingsIntegrationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@
5858
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
5959
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
6060
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
61+
import org.apache.fineract.integrationtests.common.savings.SavingsTestLifecycleExtension;
6162
import org.apache.fineract.portfolio.charge.domain.ChargeTimeType;
6263
import org.junit.jupiter.api.AfterEach;
6364
import org.junit.jupiter.api.Assertions;
6465
import org.junit.jupiter.api.BeforeEach;
6566
import org.junit.jupiter.api.Order;
6667
import org.junit.jupiter.api.Test;
68+
import org.junit.jupiter.api.extension.ExtendWith;
6769
import org.slf4j.Logger;
6870
import org.slf4j.LoggerFactory;
6971

@@ -72,6 +74,7 @@
7274
*/
7375
@SuppressWarnings({ "rawtypes" })
7476
@Order(2)
77+
@ExtendWith({ SavingsTestLifecycleExtension.class })
7578
public class ClientSavingsIntegrationTest {
7679

7780
private static final Logger LOG = LoggerFactory.getLogger(ClientSavingsIntegrationTest.class);

integration-tests/src/test/java/org/apache/fineract/integrationtests/FlexibleSavingsInterestPostingIntegrationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@
3737
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
3838
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
3939
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
40+
import org.apache.fineract.integrationtests.common.savings.SavingsTestLifecycleExtension;
4041
import org.junit.jupiter.api.AfterEach;
4142
import org.junit.jupiter.api.Assertions;
4243
import org.junit.jupiter.api.BeforeEach;
4344
import org.junit.jupiter.api.Test;
45+
import org.junit.jupiter.api.extension.ExtendWith;
4446
import org.slf4j.Logger;
4547
import org.slf4j.LoggerFactory;
4648

4749
@SuppressWarnings({ "rawtypes", "unused", "unchecked" })
50+
@ExtendWith({ SavingsTestLifecycleExtension.class })
4851
public class FlexibleSavingsInterestPostingIntegrationTest {
4952

5053
private static final Logger LOG = LoggerFactory.getLogger(FlexibleSavingsInterestPostingIntegrationTest.class);

integration-tests/src/test/java/org/apache/fineract/integrationtests/GroupSavingsIntegrationTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,19 @@
4646
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
4747
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
4848
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
49+
import org.apache.fineract.integrationtests.common.savings.SavingsTestLifecycleExtension;
4950
import org.junit.jupiter.api.Assertions;
5051
import org.junit.jupiter.api.BeforeEach;
5152
import org.junit.jupiter.api.Test;
53+
import org.junit.jupiter.api.extension.ExtendWith;
5254
import org.slf4j.Logger;
5355
import org.slf4j.LoggerFactory;
5456

5557
/**
5658
* Group Savings Integration Test for checking Savings Application.
5759
*/
5860
@SuppressWarnings({ "rawtypes", "unused" })
61+
@ExtendWith({ SavingsTestLifecycleExtension.class })
5962
public class GroupSavingsIntegrationTest {
6063

6164
public static final String DEPOSIT_AMOUNT = "2000";

integration-tests/src/test/java/org/apache/fineract/integrationtests/SavingsAccountBalanceCheckAfterReversalTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@
3434
import org.apache.fineract.integrationtests.common.savings.SavingsAccountHelper;
3535
import org.apache.fineract.integrationtests.common.savings.SavingsProductHelper;
3636
import org.apache.fineract.integrationtests.common.savings.SavingsStatusChecker;
37+
import org.apache.fineract.integrationtests.common.savings.SavingsTestLifecycleExtension;
3738
import org.junit.jupiter.api.Assertions;
3839
import org.junit.jupiter.api.BeforeEach;
3940
import org.junit.jupiter.api.Test;
41+
import org.junit.jupiter.api.extension.ExtendWith;
4042

43+
@ExtendWith({ SavingsTestLifecycleExtension.class })
4144
public class SavingsAccountBalanceCheckAfterReversalTest {
4245

4346
public static final String ACCOUNT_TYPE_INDIVIDUAL = "INDIVIDUAL";

0 commit comments

Comments
 (0)