|
19 | 19 |
|
20 | 20 | package org.apache.fineract.integrationtests; |
21 | 21 |
|
22 | | -import static io.restassured.http.ContentType.JSON; |
23 | | -import static org.apache.fineract.integrationtests.common.Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey; |
24 | 22 | import static org.apache.fineract.integrationtests.common.Utils.uniqueRandomStringGenerator; |
25 | | -import static org.hamcrest.Matchers.equalTo; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 24 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
26 | 25 |
|
27 | | -import io.restassured.builder.RequestSpecBuilder; |
28 | | -import io.restassured.builder.ResponseSpecBuilder; |
29 | | -import io.restassured.specification.RequestSpecification; |
30 | | -import io.restassured.specification.ResponseSpecification; |
31 | | -import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder; |
32 | | -import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension; |
33 | | -import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; |
34 | | -import org.junit.jupiter.api.BeforeEach; |
| 26 | +import org.apache.fineract.client.models.PostLoanProductsRequest; |
| 27 | +import org.apache.fineract.client.util.CallFailedRuntimeException; |
| 28 | +import org.apache.fineract.client.util.Calls; |
| 29 | +import org.apache.fineract.integrationtests.common.FineractClientHelper; |
35 | 30 | import org.junit.jupiter.api.Test; |
36 | | -import org.junit.jupiter.api.extension.ExtendWith; |
37 | 31 |
|
38 | | -@ExtendWith(LoanTestLifecycleExtension.class) |
39 | 32 | public class LoanProductShortNameValidationTest { |
40 | 33 |
|
41 | | - private RequestSpecification requestSpec; |
42 | | - |
43 | | - @BeforeEach |
44 | | - public void setup() { |
45 | | - requestSpec = new RequestSpecBuilder().setContentType(JSON) |
46 | | - .addHeader("Authorization", "Basic " + loginIntoServerAndGetBase64EncodedAuthenticationKey()).build(); |
47 | | - } |
48 | | - |
49 | 34 | @Test |
50 | 35 | public void createLoanProductsWithSameShortName() { |
51 | 36 | String shortName = uniqueRandomStringGenerator("", 4); |
52 | | - createLoanProduct(shortName, successResponseSpec()); |
53 | | - createLoanProduct(shortName, validationFailedResponseSpec()); |
54 | | - } |
| 37 | + PostLoanProductsRequest request = buildMinimalLoanProductRequest(shortName); |
55 | 38 |
|
56 | | - private ResponseSpecification successResponseSpec() { |
57 | | - return new ResponseSpecBuilder().expectStatusCode(200).build(); |
58 | | - } |
| 39 | + // First creation should succeed |
| 40 | + Calls.ok(FineractClientHelper.getFineractClient().loanProducts.createLoanProduct(request)); |
59 | 41 |
|
60 | | - private ResponseSpecification validationFailedResponseSpec() { |
61 | | - return new ResponseSpecBuilder().expectBody("userMessageGlobalisationCode", equalTo("error.msg.product.loan.duplicate.short.name")) |
62 | | - .expectStatusCode(403).build(); |
| 42 | + // Second creation with same short name should fail with 403 |
| 43 | + CallFailedRuntimeException exception = assertThrows(CallFailedRuntimeException.class, |
| 44 | + () -> Calls.ok(FineractClientHelper.getFineractClient().loanProducts.createLoanProduct(request))); |
| 45 | + assertEquals(403, exception.getResponse().code()); |
63 | 46 | } |
64 | 47 |
|
65 | | - private void createLoanProduct(String shortName, ResponseSpecification responseSpec) { |
66 | | - LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec); |
67 | | - |
68 | | - final String loanProductJSON = new LoanProductTestBuilder().withPrincipal("10000").withRepaymentAfterEvery("1") |
69 | | - .withShortName(shortName).withRepaymentTypeAsMonth().withInterestRateFrequencyTypeAsMonths().build(null); |
70 | | - |
71 | | - loanTransactionHelper.getLoanProductId(loanProductJSON); |
| 48 | + private PostLoanProductsRequest buildMinimalLoanProductRequest(String shortName) { |
| 49 | + return new PostLoanProductsRequest().name(uniqueRandomStringGenerator("LoanProduct_", 4)).shortName(shortName).principal(10000.0) |
| 50 | + .numberOfRepayments(5).repaymentEvery(1).repaymentFrequencyType(2L).interestRatePerPeriod(2.0).interestRateFrequencyType(2) |
| 51 | + .amortizationType(1).interestType(0).transactionProcessingStrategyCode("mifos-standard-strategy").currencyCode("USD") |
| 52 | + .digitsAfterDecimal(2).inMultiplesOf(0).locale("en").dateFormat("dd MMMM yyyy").interestCalculationPeriodType(1) |
| 53 | + .daysInYearType(1).daysInMonthType(1).isInterestRecalculationEnabled(false).accountingRule(1); |
72 | 54 | } |
73 | 55 | } |
0 commit comments