Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LY Corporation
* Copyright 2026 LY Corporation
*
* LY Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
Expand All @@ -18,6 +18,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -49,11 +50,12 @@ public static EffectiveVariant fromValue(String value) {
throw IllegalEnumValueException.causedByBlankValue();
}

if (!BY_VALUE.containsKey(value)) {
final String normalizedValue = normalize(value);
if (!BY_VALUE.containsKey(normalizedValue)) {
throw IllegalEnumValueException.causedByInvalidValue(value);
}

return BY_VALUE.get(value);
return BY_VALUE.get(normalizedValue);
}

private final List<String> values;
Expand All @@ -68,7 +70,11 @@ public String toValue() {
}

public static Boolean isValid(String value) {
return BY_VALUE.containsKey(value.toLowerCase());
return value != null && BY_VALUE.containsKey(normalize(value));
}

private static String normalize(String value) {
return value.toLowerCase(Locale.ROOT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ void isFeatureFlagOnMapsEveryEffectiveVariantAlias(String variantKey, boolean ex
assertEquals(expected, openFlagr.isFeatureFlagOn(FLAG_KEY));
}

@ParameterizedTest
@CsvSource({ "ON,true", "True,true", "Off,false", "FALSE,false" })
void isFeatureFlagOnMapsEffectiveVariantAliasesRegardlessOfCase(String variantKey, boolean expected) {
enqueueEvaluation(variantKey);

assertEquals(expected, openFlagr.isFeatureFlagOn(FLAG_KEY));
}

@Test
void isFeatureFlagOnFallsBackToFalseWhenVariantIsNotAnEffectiveVariant() {
enqueueEvaluation("control");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -47,6 +49,12 @@ void fromValueResolvesEveryOffAlias(String value) {
assertSame(EffectiveVariant.OFF, EffectiveVariant.fromValue(value));
}

@ParameterizedTest
@CsvSource({ "ON,ON", "On,ON", "TRUE,ON", "True,ON", "OFF,OFF", "Off,OFF", "FALSE,OFF" })
void fromValueResolvesAliasesRegardlessOfCase(String value, EffectiveVariant expected) {
assertSame(expected, EffectiveVariant.fromValue(value));
}

@ParameterizedTest
@NullAndEmptySource
@ValueSource(strings = { " ", "\t" })
Expand All @@ -59,7 +67,7 @@ void fromValueRejectsBlankValue(String value) {
}

@ParameterizedTest
@ValueSource(strings = { "ON", "Off", "yes", "2" })
@ValueSource(strings = { "yes", "2", "onn" })
void fromValueRejectsUnknownValue(String value) {
final IllegalEnumValueException ex =
assertThrows(IllegalEnumValueException.class, () -> EffectiveVariant.fromValue(value));
Expand All @@ -81,6 +89,7 @@ void isValidAcceptsAliasesRegardlessOfCase(String value) {
}

@ParameterizedTest
@NullSource
@ValueSource(strings = { "", " ", "yes", "2", "onn" })
void isValidRejectsUnknownValue(String value) {
assertFalse(EffectiveVariant.isValid(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ void booleanEvaluationMapsEveryEffectiveVariantAlias(String variantKey, boolean
assertNull(evaluation.getErrorCode());
}

@ParameterizedTest
@CsvSource({ "ON,true", "True,true", "Off,false", "FALSE,false" })
void booleanEvaluationMapsEffectiveVariantAliasesRegardlessOfCase(String variantKey, boolean expected) {
givenEvaluation(variantKey);

final ProviderEvaluation<Boolean> evaluation =
provider.getBooleanEvaluation(FLAG_KEY, !expected, new ImmutableContext());

assertEquals(expected, evaluation.getValue());
assertEquals(Reason.DEFAULT.name(), evaluation.getReason());
assertEquals(variantKey, evaluation.getVariant());
assertNull(evaluation.getErrorCode());
}

@Test
void booleanEvaluationFallsBackToTheDefaultValueOnANonBooleanVariant() {
givenEvaluation("control");
Expand Down
Loading