Skip to content
Snippets Groups Projects
Commit 20c9d2ce authored by Felix Reichenbach's avatar Felix Reichenbach
Browse files

OZG-7609 apply code review changes

parent 371cbe04
1 merge request!11OZG-7609 provide aggregation manager config endpoint without auhtantication
......@@ -38,5 +38,5 @@ interface AggregationMappingRepository extends MongoRepository<AggregationMappin
List<AggregationMapping> findAll();
@Query("{}")
List<AggregationMapping> findAllUnsecured();
List<AggregationMapping> findAllBypassAuth();
}
......@@ -40,7 +40,7 @@ class ReportingAggregationManagerSettingDtoService implements SettingDtoService
@Override
public ReportingAggregationManagerSettingDto getDataTransferObject() {
return mapToDto(repository.findAllUnsecured());
return mapToDto(repository.findAllBypassAuth());
}
ReportingAggregationManagerSettingDto mapToDto(List<AggregationMapping> aggregationMappings) {
......
......@@ -63,7 +63,7 @@ public class AggregationMappingEnvironmentSettingITCase {
var result = getAggregationSettings();
assertThat(result.andReturn().getResponse().getContentAsString())
.isEqualTo(PropertiesTestFactory.createAggregationProperties());
.isEqualToIgnoringWhitespace(PropertiesTestFactory.createAggregationProperties());
}
private ResultActions getAggregationSettings() throws Exception {
......
......@@ -26,6 +26,7 @@ package de.ozgcloud.admin.reporting;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
......@@ -50,32 +51,37 @@ class AggregationMappingRepositoryITCase {
operations.dropCollection(AggregationMapping.COLLECTION_NAME);
}
@Test
@WithMockUser(roles = UserRole.DATENBEAUFTRAGUNG)
void shouldLoadOnlyFieldMapping() {
operations.save(AggregationMappingTestFactory.create());
operations.save(SettingTestFactory.create());
@Nested
class TestFindAll {
@Test
@WithMockUser(roles = UserRole.DATENBEAUFTRAGUNG)
void shouldLoadOnlyFieldMapping() {
operations.save(AggregationMappingTestFactory.create());
operations.save(SettingTestFactory.create());
var result = repository.findAll();
var result = repository.findAll();
assertThat(result).hasSize(1);
}
@Test
void shouldLoadWithoutRole() {
operations.save(AggregationMappingTestFactory.create());
assertThat(result).hasSize(1);
}
var result = repository.findAllUnsecured();
@Test
@WithMockUser
void shouldThrowExceptionOnMissingRole() {
operations.save(AggregationMappingTestFactory.create());
assertThat(result).hasSize(1);
assertThatThrownBy(() -> repository.findAll()).isInstanceOf(AuthorizationDeniedException.class);
}
}
@Test
@WithMockUser
void shouldThrowExceptionOnMissingRole() {
operations.save(AggregationMappingTestFactory.create());
@Nested
class TestFindAllBypassAuth {
@Test
void shouldLoadWithoutRole() {
operations.save(AggregationMappingTestFactory.create());
assertThatThrownBy(() -> repository.findAll()).isInstanceOf(AuthorizationDeniedException.class);
}
var result = repository.findAllBypassAuth();
assertThat(result).hasSize(1);
}
}
}
......@@ -88,13 +88,13 @@ class ReportingAggregationManagerSettingDtoServiceTest {
void shouldCallRepository() {
service.getDataTransferObject();
verify(repository).findAllUnsecured();
verify(repository).findAllBypassAuth();
}
@Test
void shouldCallMapToDto() {
AggregationMapping mapping = AggregationMappingTestFactory.create();
when(repository.findAllUnsecured()).thenReturn(List.of(mapping));
when(repository.findAllBypassAuth()).thenReturn(List.of(mapping));
service.getDataTransferObject();
......
......@@ -73,7 +73,7 @@ public class PropertiesTestFactory {
}
public static String createAggregationProperties() {
return TestUtils.loadTextFile("yamlTemplates/settings/aggregation.json.tmpl",
return TestUtils.loadTextFile("jsonTemplates/settings/aggregation.json.tmpl",
FORM_ENGINE_NAME_1,
FORM_ID_1,
SOURCE_PATH_1_1,
......
{
"name": "OzgCloud_AggregationManager",
"profiles": [
"default"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "",
"source": {
"ozgcloud.aggregation.aggregationMappings[0].formIdentifier.formEngineName": "%s",
"ozgcloud.aggregation.aggregationMappings[0].formIdentifier.formId": "%s",
"ozgcloud.aggregation.aggregationMappings[0].fieldMappings[0].sourcePath": "%s",
"ozgcloud.aggregation.aggregationMappings[0].fieldMappings[0].targetPath": "%s",
"ozgcloud.aggregation.aggregationMappings[0].fieldMappings[1].sourcePath": "%s",
"ozgcloud.aggregation.aggregationMappings[0].fieldMappings[1].targetPath": "%s",
"ozgcloud.aggregation.aggregationMappings[0].fieldMappings[2].sourcePath": "%s",
"ozgcloud.aggregation.aggregationMappings[0].fieldMappings[2].targetPath": "%s",
"ozgcloud.aggregation.aggregationMappings[1].formIdentifier.formEngineName": "%s",
"ozgcloud.aggregation.aggregationMappings[1].formIdentifier.formId": "%s",
"ozgcloud.aggregation.aggregationMappings[1].fieldMappings[0].sourcePath": "%s",
"ozgcloud.aggregation.aggregationMappings[1].fieldMappings[0].targetPath": "%s",
"ozgcloud.aggregation.aggregationMappings[1].fieldMappings[1].sourcePath": "%s",
"ozgcloud.aggregation.aggregationMappings[1].fieldMappings[1].targetPath": "%s"
}
}
]
}
\ No newline at end of file
{"name":"OzgCloud_AggregationManager","profiles":["default"],"label":null,"version":null,"state":null,"propertySources":[{"name":"","source":{"ozgcloud.aggregation.aggregationMappings[0].formIdentifier.formEngineName":"%s","ozgcloud.aggregation.aggregationMappings[0].formIdentifier.formId":"%s","ozgcloud.aggregation.aggregationMappings[0].fieldMappings[0].sourcePath":"%s","ozgcloud.aggregation.aggregationMappings[0].fieldMappings[0].targetPath":"%s","ozgcloud.aggregation.aggregationMappings[0].fieldMappings[1].sourcePath":"%s","ozgcloud.aggregation.aggregationMappings[0].fieldMappings[1].targetPath":"%s","ozgcloud.aggregation.aggregationMappings[0].fieldMappings[2].sourcePath":"%s","ozgcloud.aggregation.aggregationMappings[0].fieldMappings[2].targetPath":"%s","ozgcloud.aggregation.aggregationMappings[1].formIdentifier.formEngineName":"%s","ozgcloud.aggregation.aggregationMappings[1].formIdentifier.formId":"%s","ozgcloud.aggregation.aggregationMappings[1].fieldMappings[0].sourcePath":"%s","ozgcloud.aggregation.aggregationMappings[1].fieldMappings[0].targetPath":"%s","ozgcloud.aggregation.aggregationMappings[1].fieldMappings[1].sourcePath":"%s","ozgcloud.aggregation.aggregationMappings[1].fieldMappings[1].targetPath":"%s"}}]}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment