Skip to content
Snippets Groups Projects
Commit 8bfc56e8 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-4375 OZG-4867 CR

parent 799523e5
No related branches found
No related tags found
No related merge requests found
...@@ -12,26 +12,26 @@ class FormDataExportAdjuster { ...@@ -12,26 +12,26 @@ class FormDataExportAdjuster {
static final String VALUE_KEY = "value"; static final String VALUE_KEY = "value";
public static Map<String, Object> adjustFormDataForExport(Map<String, Object> formData) { public static Map<String, Object> adjustFormDataForExport(Map<String, Object> formData) {
return removeValueKeys(formData); return replaceValueKeys(formData);
} }
static Map<String, Object> removeValueKeys(Map<String, Object> formData) { static Map<String, Object> replaceValueKeys(Map<String, Object> formData) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
for (var entry : formData.entrySet()) { for (var entry : formData.entrySet()) {
result.put(entry.getKey(), removeValueKeysFromValue(entry.getValue())); result.put(entry.getKey(), replaceValueKeysInValue(entry.getValue()));
} }
return result; return result;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static Object removeValueKeysFromValue(Object value) { private static Object replaceValueKeysInValue(Object value) {
if (!(value instanceof Map)) { if (!(value instanceof Map)) {
return value; return value;
} }
Map<String, Object> formData = (Map<String, Object>) value; Map<String, Object> formData = (Map<String, Object>) value;
return containsValueKeyOnly(formData) ? return containsValueKeyOnly(formData) ?
removeValueKeysFromValue(formData.get(VALUE_KEY)) : replaceValueKeysInValue(formData.get(VALUE_KEY)) :
removeValueKeys(formData); replaceValueKeys(formData);
} }
private static boolean containsValueKeyOnly(Map<String, Object> formData) { private static boolean containsValueKeyOnly(Map<String, Object> formData) {
......
...@@ -17,25 +17,25 @@ public class FormDataExportAdjusterTest { ...@@ -17,25 +17,25 @@ public class FormDataExportAdjusterTest {
private final Map<String, Object> formData = Map.of("key", "value"); private final Map<String, Object> formData = Map.of("key", "value");
@Test @Test
void shouldCallRemoveValueKeys() { void shouldCallReplaceValueKeys() {
try (MockedStatic<FormDataExportAdjuster> adjusterMock = mockStatic(FormDataExportAdjuster.class)) { try (MockedStatic<FormDataExportAdjuster> adjusterMock = mockStatic(FormDataExportAdjuster.class)) {
adjusterMock.when(() -> FormDataExportAdjuster.adjustFormDataForExport(any())).thenCallRealMethod(); adjusterMock.when(() -> FormDataExportAdjuster.adjustFormDataForExport(any())).thenCallRealMethod();
FormDataExportAdjuster.adjustFormDataForExport(formData); FormDataExportAdjuster.adjustFormDataForExport(formData);
adjusterMock.verify(() -> FormDataExportAdjuster.removeValueKeys(formData)); adjusterMock.verify(() -> FormDataExportAdjuster.replaceValueKeys(formData));
} }
} }
} }
@Nested @Nested
class TestRemoveValueKeys { class TestReplaceValueKeys {
@Test @Test
void shouldPreserveValueKeyWithoutParent() { void shouldPreserveValueKeyWithoutParent() {
Map<String, Object> formData = Map.of("value", "Kiel"); Map<String, Object> formData = Map.of("value", "Kiel");
var formDataWithoutValueKeys = FormDataExportAdjuster.removeValueKeys(formData); var formDataWithoutValueKeys = FormDataExportAdjuster.replaceValueKeys(formData);
assertThat(formDataWithoutValueKeys).isEqualTo(formData); assertThat(formDataWithoutValueKeys).isEqualTo(formData);
} }
...@@ -45,7 +45,7 @@ public class FormDataExportAdjusterTest { ...@@ -45,7 +45,7 @@ public class FormDataExportAdjusterTest {
Map<String, Object> formData = Map.of("ort", Map.of("value", "Kiel")); Map<String, Object> formData = Map.of("ort", Map.of("value", "Kiel"));
Map<String, Object> expected = Map.of("ort", "Kiel"); Map<String, Object> expected = Map.of("ort", "Kiel");
var formDataWithoutValueKeys = FormDataExportAdjuster.removeValueKeys(formData); var formDataWithoutValueKeys = FormDataExportAdjuster.replaceValueKeys(formData);
assertThat(formDataWithoutValueKeys).isEqualTo(expected); assertThat(formDataWithoutValueKeys).isEqualTo(expected);
} }
...@@ -54,7 +54,7 @@ public class FormDataExportAdjusterTest { ...@@ -54,7 +54,7 @@ public class FormDataExportAdjusterTest {
void shouldPreserveValueKeyIfHasSiblings() { void shouldPreserveValueKeyIfHasSiblings() {
Map<String, Object> formData = Map.of("ort", Map.of("value", "Kiel", "value2", "Kiel")); Map<String, Object> formData = Map.of("ort", Map.of("value", "Kiel", "value2", "Kiel"));
var formDataWithoutValueKeys = FormDataExportAdjuster.removeValueKeys(formData); var formDataWithoutValueKeys = FormDataExportAdjuster.replaceValueKeys(formData);
assertThat(formDataWithoutValueKeys).isEqualTo(formData); assertThat(formDataWithoutValueKeys).isEqualTo(formData);
} }
...@@ -65,7 +65,7 @@ public class FormDataExportAdjusterTest { ...@@ -65,7 +65,7 @@ public class FormDataExportAdjusterTest {
Map.of("value", Map.of("OrganisationseinheitenAuswahl", Map.of("value", "123456")))); Map.of("value", Map.of("OrganisationseinheitenAuswahl", Map.of("value", "123456"))));
Map<String, Object> expected = Map.of("empfangendestelle", Map.of("OrganisationseinheitenAuswahl", "123456")); Map<String, Object> expected = Map.of("empfangendestelle", Map.of("OrganisationseinheitenAuswahl", "123456"));
var formDataWithoutValueKeys = FormDataExportAdjuster.removeValueKeys(formData); var formDataWithoutValueKeys = FormDataExportAdjuster.replaceValueKeys(formData);
assertThat(formDataWithoutValueKeys).isEqualTo(expected); assertThat(formDataWithoutValueKeys).isEqualTo(expected);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment