From fcd57ac27edbde58c0e96c3a73be0b9782803061 Mon Sep 17 00:00:00 2001 From: Levente Gal Date: Wed, 22 Jan 2025 11:05:40 +0200 Subject: [PATCH] #13227 Allow "+" character as a value (e.g. "A+B") in the customizable enums --- .../CustomizableEnumHelper.java | 2 +- .../CustomizableEnumFacadeEjbTest.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/sormas-api/src/main/java/de/symeda/sormas/api/customizableenum/CustomizableEnumHelper.java b/sormas-api/src/main/java/de/symeda/sormas/api/customizableenum/CustomizableEnumHelper.java index b92f344a9ae..b680e7445bc 100644 --- a/sormas-api/src/main/java/de/symeda/sormas/api/customizableenum/CustomizableEnumHelper.java +++ b/sormas-api/src/main/java/de/symeda/sormas/api/customizableenum/CustomizableEnumHelper.java @@ -19,7 +19,7 @@ public class CustomizableEnumHelper { - private static final String ENUM_VALUE_PATTERN = "[A-Z0-9_.]+"; + private static final String ENUM_VALUE_PATTERN = "[A-Z0-9_.+]+"; public static boolean isValidEnumValue(String value) { return Pattern.matches(ENUM_VALUE_PATTERN, value); diff --git a/sormas-backend/src/test/java/de/symeda/sormas/backend/customizableenum/CustomizableEnumFacadeEjbTest.java b/sormas-backend/src/test/java/de/symeda/sormas/backend/customizableenum/CustomizableEnumFacadeEjbTest.java index fc939ee2b92..d559230a300 100644 --- a/sormas-backend/src/test/java/de/symeda/sormas/backend/customizableenum/CustomizableEnumFacadeEjbTest.java +++ b/sormas-backend/src/test/java/de/symeda/sormas/backend/customizableenum/CustomizableEnumFacadeEjbTest.java @@ -1,7 +1,9 @@ package de.symeda.sormas.backend.customizableenum; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashSet; import java.util.List; @@ -13,6 +15,7 @@ import de.symeda.sormas.api.Disease; import de.symeda.sormas.api.customizableenum.CustomEnumNotFoundException; import de.symeda.sormas.api.customizableenum.CustomizableEnum; +import de.symeda.sormas.api.customizableenum.CustomizableEnumHelper; import de.symeda.sormas.api.customizableenum.CustomizableEnumType; import de.symeda.sormas.backend.AbstractBeanTest; @@ -61,4 +64,19 @@ public void tetGetUnknownDiseaseVariantWithNullDisease() throws CustomEnumNotFou CustomEnumNotFoundException.class, () -> getCustomizableEnumFacade().getEnumValue(CustomizableEnumType.DISEASE_VARIANT, "any", null)); } + + @Test + public void testEnumValueValidation() { + assertTrue(CustomizableEnumHelper.isValidEnumValue("VALIDSIMPLEVALUE")); + assertTrue(CustomizableEnumHelper.isValidEnumValue("VALID_SIMPLE_VALUE")); + assertTrue(CustomizableEnumHelper.isValidEnumValue("VALID.SIMPLE.VALUE")); + assertTrue(CustomizableEnumHelper.isValidEnumValue("VALID+SIMPLE+VALUE")); + assertTrue(CustomizableEnumHelper.isValidEnumValue("VALID_SIM+PLE.VALUE")); + assertTrue(CustomizableEnumHelper.isValidEnumValue("VALID_SIMPLE.VALUE+1")); + + assertFalse(CustomizableEnumHelper.isValidEnumValue("invalidvalue")); + assertFalse(CustomizableEnumHelper.isValidEnumValue("INVALID-VALUE")); + assertFalse(CustomizableEnumHelper.isValidEnumValue("INVALID$VALUE")); + + } }