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

OZG-4375 OZG-4867 CR

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