diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/BeaconRestApiTypes.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/BeaconRestApiTypes.java index 8f0f8872905..5d079e9f51b 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/BeaconRestApiTypes.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/BeaconRestApiTypes.java @@ -72,8 +72,8 @@ public class BeaconRestApiTypes { private static final StringValueTypeDefinition STATUS_VALUE = DeserializableTypeDefinition.string(StatusParameter.class) - .formatter(StatusParameter::toString) - .parser(StatusParameter::valueOf) + .formatter(StatusParameter::getValue) + .parser(StatusParameter::parse) .example("active_ongoing") .description("ValidatorStatus string") .format("string") diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/StatusParameter.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/StatusParameter.java index 48fc2490943..1f15312f2ac 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/StatusParameter.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/StatusParameter.java @@ -15,25 +15,39 @@ import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.stream.Collectors; import tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus; -@SuppressWarnings("JavaCase") public enum StatusParameter { - pending_initialized, - pending_queued, - active_ongoing, - active_exiting, - active_slashed, - exited_unslashed, - exited_slashed, - withdrawal_possible, - withdrawal_done, - active, - pending, - exited, - withdrawal; + PENDING_INITIALIZED("pending_initialized"), + PENDING_QUEUED("pending_queued"), + ACTIVE_ONGOING("active_ongoing"), + ACTIVE_EXITING("active_exiting"), + ACTIVE_SLASHED("active_slashed"), + EXITED_UNSLASHED("exited_unslashed"), + EXITED_SLASHED("exited_slashed"), + WITHDRAWAL_POSSIBLE("withdrawal_possible"), + WITHDRAWAL_DONE("withdrawal_done"), + ACTIVE("active"), + PENDING("pending"), + EXITED("exited"), + WITHDRAWAL("withdrawal"); + + private final String value; + + StatusParameter(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static StatusParameter parse(final String value) { + return StatusParameter.valueOf(value.toUpperCase(Locale.ROOT)); + } public static Set getApplicableValidatorStatuses( final List statusParameters) { @@ -42,7 +56,8 @@ public static Set getApplicableValidatorStatuses( statusParameter -> Arrays.stream(ValidatorStatus.values()) .filter( - validatorStatus -> validatorStatus.name().contains(statusParameter.name()))) + validatorStatus -> + validatorStatus.name().contains(statusParameter.getValue()))) .collect(Collectors.toSet()); } } diff --git a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetStateValidatorsTest.java b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetStateValidatorsTest.java index c3f7ec8244b..17a47e24a23 100644 --- a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetStateValidatorsTest.java +++ b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/GetStateValidatorsTest.java @@ -196,7 +196,8 @@ void statusParameterEnumContainsAllValidatorStatuses() { validatorStatus -> Arrays.stream(StatusParameter.values()) .anyMatch( - statusParameter -> statusParameter.name().equals(validatorStatus.name()))); + statusParameter -> + statusParameter.getValue().equals(validatorStatus.name()))); } private static Stream provideStatusParameters() { diff --git a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostStateValidatorsTest.java b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostStateValidatorsTest.java index ca927c71618..4f9f12cf1e2 100644 --- a/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostStateValidatorsTest.java +++ b/data/beaconrestapi/src/test/java/tech/pegasys/teku/beaconrestapi/handlers/v1/beacon/PostStateValidatorsTest.java @@ -26,10 +26,10 @@ import static tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus.pending_queued; import static tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus.withdrawal_done; import static tech.pegasys.teku.api.response.v1.beacon.ValidatorStatus.withdrawal_possible; -import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.active; -import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.exited; -import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.pending; -import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.withdrawal; +import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.ACTIVE; +import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.EXITED; +import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.PENDING; +import static tech.pegasys.teku.beaconrestapi.handlers.v1.beacon.StatusParameter.WITHDRAWAL; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_BAD_REQUEST; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_INTERNAL_SERVER_ERROR; import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NOT_FOUND; @@ -99,9 +99,9 @@ public void shouldGetValidatorFromStateWithList() throws Exception { new PostStateValidators.RequestBody( List.of("1", "2"), List.of( - StatusParameter.active_ongoing, - StatusParameter.active_exiting, - StatusParameter.withdrawal_done)); + StatusParameter.ACTIVE_ONGOING, + StatusParameter.ACTIVE_EXITING, + StatusParameter.WITHDRAWAL_DONE)); final StubRestApiRequest request = StubRestApiRequest.builder() .metadata(handler.getMetadata()) @@ -212,14 +212,15 @@ void statusParameterEnumContainsAllValidatorStatuses() { validatorStatus -> Arrays.stream(StatusParameter.values()) .anyMatch( - statusParameter -> statusParameter.name().equals(validatorStatus.name()))); + statusParameter -> + statusParameter.getValue().equals(validatorStatus.name()))); } private static Stream provideStatusParameters() { return Stream.of( - Arguments.of(List.of(active), Set.of(active_ongoing, active_exiting, active_slashed)), - Arguments.of(List.of(pending), Set.of(pending_initialized, pending_queued)), - Arguments.of(List.of(exited), Set.of(exited_slashed, exited_unslashed)), - Arguments.of(List.of(withdrawal), Set.of(withdrawal_done, withdrawal_possible))); + Arguments.of(List.of(ACTIVE), Set.of(active_ongoing, active_exiting, active_slashed)), + Arguments.of(List.of(PENDING), Set.of(pending_initialized, pending_queued)), + Arguments.of(List.of(EXITED), Set.of(exited_slashed, exited_unslashed)), + Arguments.of(List.of(WITHDRAWAL), Set.of(withdrawal_done, withdrawal_possible))); } }