Skip to content

Commit

Permalink
#13227 Allow "+" character as a value (e.g. "A+B") in the customizabl…
Browse files Browse the repository at this point in the history
…e enums
  • Loading branch information
Levente Gal committed Jan 22, 2025
1 parent dafe50a commit fcd57ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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"));

}
}

0 comments on commit fcd57ac

Please sign in to comment.