FINERACT-2081: Retrieving Loan Product details with invalid external-id results in 500 error
This commit is contained in:
committed by
Adam Saghy
parent
d57e72ec2f
commit
8d12bc04e9
+2
-1
@@ -32,7 +32,8 @@ public class LoanProductNotFoundException extends AbstractPlatformResourceNotFou
|
||||
}
|
||||
|
||||
public LoanProductNotFoundException(final ExternalId externalId) {
|
||||
super("error.msg.loanproduct.id.invalid", "Loan product with identifier " + externalId + " does not exist", externalId);
|
||||
super("error.msg.loanproduct.id.invalid", "Loan product with identifier " + externalId.getValue() + " does not exist",
|
||||
externalId.getValue());
|
||||
}
|
||||
|
||||
public LoanProductNotFoundException(Long id, EmptyResultDataAccessException e) {
|
||||
|
||||
+5
-1
@@ -104,7 +104,11 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo
|
||||
|
||||
@Override
|
||||
public LoanProduct retrieveLoanProductByExternalId(final ExternalId externalId) {
|
||||
return loanProductRepository.findByExternalId(externalId);
|
||||
final LoanProduct loanProduct = loanProductRepository.findByExternalId(externalId);
|
||||
if (loanProduct == null) {
|
||||
throw new LoanProductNotFoundException(externalId);
|
||||
}
|
||||
return loanProduct;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+21
@@ -20,6 +20,8 @@ package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.builder.ResponseSpecBuilder;
|
||||
@@ -31,6 +33,7 @@ import java.util.UUID;
|
||||
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse;
|
||||
import org.apache.fineract.client.models.PutLoanProductsProductIdRequest;
|
||||
import org.apache.fineract.client.models.PutLoanProductsProductIdResponse;
|
||||
import org.apache.fineract.client.util.CallFailedRuntimeException;
|
||||
import org.apache.fineract.integrationtests.common.Utils;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductHelper;
|
||||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder;
|
||||
@@ -73,4 +76,22 @@ public class LoanProductExternalIdTest {
|
||||
assertNotNull(putLoanProductsProductIdResponse.getResourceId());
|
||||
assertEquals(loanProductId, putLoanProductsProductIdResponse.getResourceId().intValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoanProductWithInvalidExternalId() {
|
||||
String externalId = UUID.randomUUID().toString();
|
||||
HashMap<String, Object> request = new LoanProductTestBuilder().withExternalId(externalId).build(null, null);
|
||||
Integer loanProductId = loanTransactionHelper.getLoanProductId(Utils.convertToJson(request));
|
||||
assertNotNull(loanProductId);
|
||||
|
||||
GetLoanProductsProductIdResponse getLoanProductsProductIdResponse = loanProductHelper.retrieveLoanProductByExternalId(externalId);
|
||||
assertNotNull(getLoanProductsProductIdResponse.getId());
|
||||
assertEquals(loanProductId, getLoanProductsProductIdResponse.getId().intValue());
|
||||
|
||||
CallFailedRuntimeException exception = assertThrows(CallFailedRuntimeException.class,
|
||||
() -> loanProductHelper.retrieveLoanProductByExternalId(externalId.substring(2)));
|
||||
assertEquals(404, exception.getResponse().code());
|
||||
assertTrue(exception.getMessage().contains("error.msg.loanproduct.id.invalid"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user