FINERACT-2181: fixed ConfigurationReadPlatformServiceImpl to handle not found cases, added tests
This commit is contained in:
+1
-1
@@ -106,7 +106,7 @@ public class GlobalConfigurationApiResource {
|
||||
@Operation(summary = "Retrieve Global Configuration", description = "Returns a global enable/disable configurations.\n" + "\n"
|
||||
+ "Example Requests:\n" + "\n" + "configurations/1")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GlobalConfigurationApiResourceSwagger.GetGlobalConfigurationsResponse.class))) })
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = GlobalConfigurationPropertyData.class))) })
|
||||
public String retrieveOne(@PathParam("configId") @Parameter(description = "configId") final Long configId,
|
||||
@Context final UriInfo uriInfo) {
|
||||
|
||||
|
||||
+10
-10
@@ -25,6 +25,8 @@ import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import org.apache.fineract.infrastructure.configuration.data.GlobalConfigurationData;
|
||||
import org.apache.fineract.infrastructure.configuration.data.GlobalConfigurationPropertyData;
|
||||
import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationProperty;
|
||||
import org.apache.fineract.infrastructure.configuration.domain.GlobalConfigurationRepositoryWrapper;
|
||||
import org.apache.fineract.infrastructure.dataqueries.api.DataTableApiConstant;
|
||||
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -37,12 +39,15 @@ public class ConfigurationReadPlatformServiceImpl implements ConfigurationReadPl
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final GlobalConfigurationRepositoryWrapper configurationRepositoryWrapper;
|
||||
private final RowMapper<GlobalConfigurationPropertyData> rm;
|
||||
|
||||
@Autowired
|
||||
public ConfigurationReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate) {
|
||||
public ConfigurationReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate,
|
||||
final GlobalConfigurationRepositoryWrapper configurationRepositoryWrapper) {
|
||||
this.context = context;
|
||||
this.jdbcTemplate = jdbcTemplate;
|
||||
this.configurationRepositoryWrapper = configurationRepositoryWrapper;
|
||||
|
||||
this.rm = new GlobalConfigurationRowMapper();
|
||||
}
|
||||
@@ -72,11 +77,9 @@ public class ConfigurationReadPlatformServiceImpl implements ConfigurationReadPl
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final String sql = "SELECT c.id, c.name, c.enabled, c.value, c.date_value, c.string_value, c.description, c.is_trap_door FROM "
|
||||
+ "c_configuration c where c.name=? order by c.id";
|
||||
final GlobalConfigurationPropertyData globalConfiguration = this.jdbcTemplate.queryForObject(sql, this.rm, new Object[] { name });
|
||||
GlobalConfigurationProperty globalConfigurationProperty = configurationRepositoryWrapper.findOneByNameWithNotFoundDetection(name);
|
||||
|
||||
return globalConfiguration;
|
||||
return globalConfigurationProperty.toData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,12 +87,9 @@ public class ConfigurationReadPlatformServiceImpl implements ConfigurationReadPl
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final String sql = "SELECT c.id, c.name, c.enabled, c.value, c.date_value, c.string_value ,c.description, c.is_trap_door FROM "
|
||||
+ "c_configuration c where c.id=? order by c.id";
|
||||
final GlobalConfigurationPropertyData globalConfiguration = this.jdbcTemplate.queryForObject(sql, this.rm,
|
||||
new Object[] { configId });
|
||||
GlobalConfigurationProperty globalConfigurationProperty = configurationRepositoryWrapper.findOneWithNotFoundDetection(configId);
|
||||
|
||||
return globalConfiguration;
|
||||
return globalConfigurationProperty.toData();
|
||||
}
|
||||
|
||||
private static final class GlobalConfigurationRowMapper implements RowMapper<GlobalConfigurationPropertyData> {
|
||||
|
||||
+18
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -27,6 +28,7 @@ import io.restassured.builder.ResponseSpecBuilder;
|
||||
import io.restassured.http.ContentType;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import io.restassured.specification.ResponseSpecification;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.fineract.client.models.GetGlobalConfigurationsResponse;
|
||||
import org.apache.fineract.client.models.GlobalConfigurationPropertyData;
|
||||
import org.apache.fineract.client.models.PutGlobalConfigurationsRequest;
|
||||
@@ -96,6 +98,22 @@ public class GlobalConfigurationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConfigurationPropertyById() {
|
||||
Long configId = 1L;
|
||||
GlobalConfigurationPropertyData configuration = assertDoesNotThrow(
|
||||
() -> globalConfigurationHelper.getGlobalConfigurationById(configId));
|
||||
assertTrue(StringUtils.isNotBlank(configuration.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotExistingConfigurationProperty() {
|
||||
String notExistingConfigName = "not-existing-configuration";
|
||||
CallFailedRuntimeException exception = assertThrows(CallFailedRuntimeException.class,
|
||||
() -> globalConfigurationHelper.getGlobalConfigurationByName(notExistingConfigName));
|
||||
assertEquals(404, exception.getResponse().code());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPasswordUpdateFailing() {
|
||||
String configName = GlobalConfigurationConstants.FORCE_PASSWORD_RESET_DAYS;
|
||||
|
||||
+2
@@ -52,8 +52,10 @@ import org.apache.fineract.portfolio.loanaccount.loanschedule.domain.LoanSchedul
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Order(1)
|
||||
public class LoanCatchUpIntegrationTest extends BaseLoanIntegrationTest {
|
||||
|
||||
private static final String REPAYMENT_LOAN_PERMISSION = "REPAYMENT_LOAN";
|
||||
|
||||
+5
@@ -52,6 +52,11 @@ public class GlobalConfigurationHelper {
|
||||
return Calls.ok(FineractClientHelper.getFineractClient().globalConfigurations.retrieveOneByName(configName));
|
||||
}
|
||||
|
||||
public GlobalConfigurationPropertyData getGlobalConfigurationById(final Long configId) {
|
||||
log.info("------------------------ RETRIEVING GLOBAL CONFIGURATION BY ID -------------------------");
|
||||
return Calls.ok(FineractClientHelper.getFineractClient().globalConfigurations.retrieveOne3(configId));
|
||||
}
|
||||
|
||||
// TODO: This is quite a bad pattern and adds a lot of time to individual test executions
|
||||
public void resetAllDefaultGlobalConfigurations() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user