FINERACT-1724: Loan product creation - duplicate short name fix
This commit is contained in:
committed by
Arnold Gálovics
parent
0109d24934
commit
573b4bb998
+10
-1
@@ -328,7 +328,8 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
|
|||||||
final String name = command.stringValueOfParameterNamed("name");
|
final String name = command.stringValueOfParameterNamed("name");
|
||||||
throw new PlatformDataIntegrityException("error.msg.product.loan.duplicate.name",
|
throw new PlatformDataIntegrityException("error.msg.product.loan.duplicate.name",
|
||||||
"Loan product with name `" + name + "` already exists", "name", name, realCause);
|
"Loan product with name `" + name + "` already exists", "name", name, realCause);
|
||||||
} else if (realCause.getMessage().contains("'unq_short_name'")) {
|
} else if (realCause.getMessage().contains("'unq_short_name'") || containsDuplicateShortnameErrorForPostgreSQL(realCause)
|
||||||
|
|| containsDuplicateShortnameErrorForMySQL(realCause)) {
|
||||||
|
|
||||||
final String shortName = command.stringValueOfParameterNamed("shortName");
|
final String shortName = command.stringValueOfParameterNamed("shortName");
|
||||||
throw new PlatformDataIntegrityException("error.msg.product.loan.duplicate.short.name",
|
throw new PlatformDataIntegrityException("error.msg.product.loan.duplicate.short.name",
|
||||||
@@ -343,6 +344,14 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
|
|||||||
"Unknown data integrity issue with resource.", realCause);
|
"Unknown data integrity issue with resource.", realCause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean containsDuplicateShortnameErrorForPostgreSQL(Throwable realCause) {
|
||||||
|
return realCause.getMessage().contains("m_product_loan_short_name_key");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean containsDuplicateShortnameErrorForMySQL(Throwable realCause) {
|
||||||
|
return (realCause.getMessage().contains("short_name") && realCause.getMessage().toLowerCase().contains("duplicate"));
|
||||||
|
}
|
||||||
|
|
||||||
private void validateInputDates(final JsonCommand command) {
|
private void validateInputDates(final JsonCommand command) {
|
||||||
final LocalDate startDate = command.localDateValueOfParameterNamed("startDate");
|
final LocalDate startDate = command.localDateValueOfParameterNamed("startDate");
|
||||||
final LocalDate closeDate = command.localDateValueOfParameterNamed("closeDate");
|
final LocalDate closeDate = command.localDateValueOfParameterNamed("closeDate");
|
||||||
|
|||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
/**
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.fineract.integrationtests;
|
||||||
|
|
||||||
|
import static io.restassured.http.ContentType.JSON;
|
||||||
|
import static org.apache.fineract.integrationtests.common.Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey;
|
||||||
|
import static org.apache.fineract.integrationtests.common.Utils.uniqueRandomStringGenerator;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
|
||||||
|
import io.restassured.builder.RequestSpecBuilder;
|
||||||
|
import io.restassured.builder.ResponseSpecBuilder;
|
||||||
|
import io.restassured.specification.RequestSpecification;
|
||||||
|
import io.restassured.specification.ResponseSpecification;
|
||||||
|
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||||
|
import org.apache.fineract.integrationtests.common.loans.LoanTestLifecycleExtension;
|
||||||
|
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
|
||||||
|
@ExtendWith(LoanTestLifecycleExtension.class)
|
||||||
|
public class LoanProductShortNameValidationTest {
|
||||||
|
|
||||||
|
private RequestSpecification requestSpec;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setup() {
|
||||||
|
requestSpec = new RequestSpecBuilder().setContentType(JSON)
|
||||||
|
.addHeader("Authorization", "Basic " + loginIntoServerAndGetBase64EncodedAuthenticationKey()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createLoanProductsWithSameShortName() {
|
||||||
|
String shortName = uniqueRandomStringGenerator("", 4);
|
||||||
|
createLoanProduct(shortName, successResponseSpec());
|
||||||
|
createLoanProduct(shortName, validationFailedResponseSpec());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResponseSpecification successResponseSpec() {
|
||||||
|
return new ResponseSpecBuilder().expectStatusCode(200).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResponseSpecification validationFailedResponseSpec() {
|
||||||
|
return new ResponseSpecBuilder().expectBody("userMessageGlobalisationCode", equalTo("error.msg.product.loan.duplicate.short.name"))
|
||||||
|
.expectStatusCode(403).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createLoanProduct(String shortName, ResponseSpecification responseSpec) {
|
||||||
|
LoanTransactionHelper loanTransactionHelper = new LoanTransactionHelper(requestSpec, responseSpec);
|
||||||
|
|
||||||
|
final String loanProductJSON = new LoanProductTestBuilder().withPrincipal("10000").withRepaymentAfterEvery("1")
|
||||||
|
.withShortName(shortName).withRepaymentTypeAsMonth().withInterestRateFrequencyTypeAsMonths().build(null);
|
||||||
|
|
||||||
|
loanTransactionHelper.getLoanProductId(loanProductJSON);
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-1
@@ -75,7 +75,7 @@ public class LoanProductTestBuilder {
|
|||||||
private String inMultiplesOf = "0";
|
private String inMultiplesOf = "0";
|
||||||
|
|
||||||
private String nameOfLoanProduct = Utils.uniqueRandomStringGenerator("LOAN_PRODUCT_", 6);
|
private String nameOfLoanProduct = Utils.uniqueRandomStringGenerator("LOAN_PRODUCT_", 6);
|
||||||
private final String shortName = Utils.uniqueRandomStringGenerator("", 4);
|
private String shortName = Utils.uniqueRandomStringGenerator("", 4);
|
||||||
private String principal = "10000.00";
|
private String principal = "10000.00";
|
||||||
private String numberOfRepayments = "5";
|
private String numberOfRepayments = "5";
|
||||||
private String repaymentFrequency = MONTHS;
|
private String repaymentFrequency = MONTHS;
|
||||||
@@ -311,6 +311,11 @@ public class LoanProductTestBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LoanProductTestBuilder withShortName(final String shortName) {
|
||||||
|
this.shortName = shortName;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public LoanProductTestBuilder withNumberOfRepayments(final String numberOfRepayment) {
|
public LoanProductTestBuilder withNumberOfRepayments(final String numberOfRepayment) {
|
||||||
this.numberOfRepayments = numberOfRepayment;
|
this.numberOfRepayments = numberOfRepayment;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Reference in New Issue
Block a user