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
No related branches found
No related tags found
1 merge request!11OZG-7609 provide aggregation manager config endpoint without auhtantication
...@@ -38,5 +38,5 @@ interface AggregationMappingRepository extends MongoRepository<AggregationMappin ...@@ -38,5 +38,5 @@ interface AggregationMappingRepository extends MongoRepository<AggregationMappin
List<AggregationMapping> findAll(); List<AggregationMapping> findAll();
@Query("{}") @Query("{}")
List<AggregationMapping> findAllUnsecured(); List<AggregationMapping> findAllBypassAuth();
} }
...@@ -40,7 +40,7 @@ class ReportingAggregationManagerSettingDtoService implements SettingDtoService ...@@ -40,7 +40,7 @@ class ReportingAggregationManagerSettingDtoService implements SettingDtoService
@Override @Override
public ReportingAggregationManagerSettingDto getDataTransferObject() { public ReportingAggregationManagerSettingDto getDataTransferObject() {
return mapToDto(repository.findAllUnsecured()); return mapToDto(repository.findAllBypassAuth());
} }
ReportingAggregationManagerSettingDto mapToDto(List<AggregationMapping> aggregationMappings) { ReportingAggregationManagerSettingDto mapToDto(List<AggregationMapping> aggregationMappings) {
......
...@@ -63,7 +63,7 @@ public class AggregationMappingEnvironmentSettingITCase { ...@@ -63,7 +63,7 @@ public class AggregationMappingEnvironmentSettingITCase {
var result = getAggregationSettings(); var result = getAggregationSettings();
assertThat(result.andReturn().getResponse().getContentAsString()) assertThat(result.andReturn().getResponse().getContentAsString())
.isEqualTo(PropertiesTestFactory.createAggregationProperties()); .isEqualToIgnoringWhitespace(PropertiesTestFactory.createAggregationProperties());
} }
private ResultActions getAggregationSettings() throws Exception { private ResultActions getAggregationSettings() throws Exception {
......
...@@ -26,6 +26,7 @@ package de.ozgcloud.admin.reporting; ...@@ -26,6 +26,7 @@ package de.ozgcloud.admin.reporting;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.MongoOperations;
...@@ -50,6 +51,8 @@ class AggregationMappingRepositoryITCase { ...@@ -50,6 +51,8 @@ class AggregationMappingRepositoryITCase {
operations.dropCollection(AggregationMapping.COLLECTION_NAME); operations.dropCollection(AggregationMapping.COLLECTION_NAME);
} }
@Nested
class TestFindAll {
@Test @Test
@WithMockUser(roles = UserRole.DATENBEAUFTRAGUNG) @WithMockUser(roles = UserRole.DATENBEAUFTRAGUNG)
void shouldLoadOnlyFieldMapping() { void shouldLoadOnlyFieldMapping() {
...@@ -62,20 +65,23 @@ class AggregationMappingRepositoryITCase { ...@@ -62,20 +65,23 @@ class AggregationMappingRepositoryITCase {
} }
@Test @Test
void shouldLoadWithoutRole() { @WithMockUser
void shouldThrowExceptionOnMissingRole() {
operations.save(AggregationMappingTestFactory.create()); operations.save(AggregationMappingTestFactory.create());
var result = repository.findAllUnsecured(); assertThatThrownBy(() -> repository.findAll()).isInstanceOf(AuthorizationDeniedException.class);
}
assertThat(result).hasSize(1);
} }
@Nested
class TestFindAllBypassAuth {
@Test @Test
@WithMockUser void shouldLoadWithoutRole() {
void shouldThrowExceptionOnMissingRole() {
operations.save(AggregationMappingTestFactory.create()); operations.save(AggregationMappingTestFactory.create());
assertThatThrownBy(() -> repository.findAll()).isInstanceOf(AuthorizationDeniedException.class); var result = repository.findAllBypassAuth();
}
assertThat(result).hasSize(1);
}
}
} }
...@@ -88,13 +88,13 @@ class ReportingAggregationManagerSettingDtoServiceTest { ...@@ -88,13 +88,13 @@ class ReportingAggregationManagerSettingDtoServiceTest {
void shouldCallRepository() { void shouldCallRepository() {
service.getDataTransferObject(); service.getDataTransferObject();
verify(repository).findAllUnsecured(); verify(repository).findAllBypassAuth();
} }
@Test @Test
void shouldCallMapToDto() { void shouldCallMapToDto() {
AggregationMapping mapping = AggregationMappingTestFactory.create(); AggregationMapping mapping = AggregationMappingTestFactory.create();
when(repository.findAllUnsecured()).thenReturn(List.of(mapping)); when(repository.findAllBypassAuth()).thenReturn(List.of(mapping));
service.getDataTransferObject(); service.getDataTransferObject();
......
...@@ -73,7 +73,7 @@ public class PropertiesTestFactory { ...@@ -73,7 +73,7 @@ public class PropertiesTestFactory {
} }
public static String createAggregationProperties() { 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_ENGINE_NAME_1,
FORM_ID_1, FORM_ID_1,
SOURCE_PATH_1_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