FINERACT-2242: New command processing - External Event Configuration (org.apache.fineract.infrastructure.event.external)

This commit is contained in:
viktorpavlenko
2025-06-26 15:37:53 +02:00
committed by Aleksandar Vidakovic
parent 86024b83cc
commit ba06234f26
34 changed files with 340 additions and 316 deletions
@@ -134,10 +134,15 @@ public class SecurityConfig {
.requestMatchers(antMatcher(HttpMethod.PUT, "/api/*/instance-mode")).permitAll() //
// businessdate
.requestMatchers(antMatcher(HttpMethod.GET, "/api/*/businessdate/*"))
.hasAnyAuthority("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", "READ_BUSINESS_DATE") //
.hasAnyAuthority("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", "READ_BUSINESS_DATE")
.requestMatchers(antMatcher(HttpMethod.POST, "/api/*/businessdate"))
.hasAnyAuthority("ALL_FUNCTIONS", "ALL_FUNCTIONS_WRITE", "UPDATE_BUSINESS_DATE") //
//
.hasAnyAuthority("ALL_FUNCTIONS", "ALL_FUNCTIONS_WRITE", "UPDATE_BUSINESS_DATE")
// external
.requestMatchers(antMatcher(HttpMethod.GET, "/api/*/externalevents/configuration"))
.hasAnyAuthority("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", "READ_EXTERNAL_EVENT_CONFIGURATION")
.requestMatchers(antMatcher(HttpMethod.PUT, "/api/*/externalevents/configuration"))
.hasAnyAuthority("ALL_FUNCTIONS", "ALL_FUNCTIONS_WRITE", "UPDATE_EXTERNAL_EVENT_CONFIGURATION")
// ...
.requestMatchers(antMatcher(HttpMethod.POST, "/api/*/twofactor/validate")).fullyAuthenticated() //
.requestMatchers(antMatcher("/api/*/twofactor")).fullyAuthenticated() //
.requestMatchers(antMatcher("/api/**"))
@@ -27,8 +27,8 @@ import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.fineract.infrastructure.event.external.data.ExternalEventConfigurationData;
import org.apache.fineract.infrastructure.event.external.data.ExternalEventConfigurationItemData;
import org.apache.fineract.infrastructure.event.external.data.ExternalEventConfigurationItemResponse;
import org.apache.fineract.infrastructure.event.external.data.ExternalEventConfigurationResponse;
import org.apache.fineract.infrastructure.event.external.repository.ExternalEventConfigurationRepository;
import org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEventConfiguration;
import org.junit.jupiter.api.BeforeEach;
@@ -59,16 +59,16 @@ public class ExternalEventConfigurationReadPlatformServiceTest {
// given
List<ExternalEventConfiguration> configurations = Arrays.asList(new ExternalEventConfiguration("aType", true),
new ExternalEventConfiguration("bType", false));
List<ExternalEventConfigurationItemData> configurationDataItems = Arrays
.asList(new ExternalEventConfigurationItemData("aType", true), new ExternalEventConfigurationItemData("bType", false));
List<ExternalEventConfigurationItemResponse> configurationDataItems = Arrays.asList(
new ExternalEventConfigurationItemResponse("aType", true), new ExternalEventConfigurationItemResponse("bType", false));
when(repository.findAll()).thenReturn(configurations);
when(mapper.map(Mockito.anyList())).thenReturn(configurationDataItems);
// when
ExternalEventConfigurationData actualConfiguration = underTest.findAllExternalEventConfigurations();
ExternalEventConfigurationResponse actualConfiguration = underTest.findAllExternalEventConfigurations();
// then
assertThat(actualConfiguration.getExternalEventConfiguration(), hasSize(2));
assertThat(actualConfiguration.getExternalEventConfiguration().get(0), any(ExternalEventConfigurationItemData.class));
assertThat(actualConfiguration.getExternalEventConfiguration().get(0), any(ExternalEventConfigurationItemResponse.class));
assertThat(actualConfiguration.getExternalEventConfiguration().get(0).getType(), equalTo("aType"));
assertThat(actualConfiguration.getExternalEventConfiguration().get(0).isEnabled(), equalTo(true));
}
@@ -79,7 +79,7 @@ public class ExternalEventConfigurationReadPlatformServiceTest {
List<ExternalEventConfiguration> emptyConfiguration = new ArrayList<>();
when(repository.findAll()).thenReturn(emptyConfiguration);
// when
ExternalEventConfigurationData actualConfiguration = underTest.findAllExternalEventConfigurations();
ExternalEventConfigurationResponse actualConfiguration = underTest.findAllExternalEventConfigurations();
// then
assertThat(actualConfiguration.getExternalEventConfiguration(), hasSize(0));
@@ -22,13 +22,10 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.Map;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.event.external.command.ExternalEventConfigurationCommand;
import org.apache.fineract.infrastructure.event.external.data.ExternalEventConfigurationUpdateRequest;
import org.apache.fineract.infrastructure.event.external.repository.ExternalEventConfigurationRepository;
import org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEventConfiguration;
import org.apache.fineract.infrastructure.event.external.serialization.ExternalEventConfigurationCommandFromApiJsonDeserializer;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -41,31 +38,26 @@ public class ExternalEventConfigurationWritePlatformServiceTest {
@Mock
private ExternalEventConfigurationRepository repository;
@Mock
private ExternalEventConfigurationCommandFromApiJsonDeserializer fromApiJsonDeserializer;
private ExternalEventConfigurationWritePlatformServiceImpl underTest;
@BeforeEach
public void setUp() {
underTest = new ExternalEventConfigurationWritePlatformServiceImpl(repository, fromApiJsonDeserializer);
underTest = new ExternalEventConfigurationWritePlatformServiceImpl(repository);
}
@Test
public void givenExternalEventConfigurationsWithChangeWhenUpdateConfigurationThenConfigurationIsUpdated() {
// given
final JsonCommand jsonCommand = Mockito.mock(JsonCommand.class);
Map<String, Boolean> mapOfConfigurationsForUpdate = new HashMap<>();
mapOfConfigurationsForUpdate.put("aType", Boolean.TRUE);
ExternalEventConfigurationCommand command = new ExternalEventConfigurationCommand(mapOfConfigurationsForUpdate);
when(jsonCommand.json()).thenReturn("");
when(fromApiJsonDeserializer.commandFromApiJson(Mockito.anyString())).thenReturn(command);
var configurations = Map.of("aType", Boolean.TRUE);
var request = new ExternalEventConfigurationUpdateRequest(configurations);
when(repository.findExternalEventConfigurationByTypeWithNotFoundDetection(Mockito.anyString()))
.thenReturn(new ExternalEventConfiguration("aType", false));
// when
underTest.updateConfigurations(jsonCommand);
underTest.updateConfigurations(request);
// then
verify(repository, times(1)).saveAll(Mockito.anyCollection());
}
}