diff --git a/java/google/registry/flows/domain/DomainFlowUtils.java b/java/google/registry/flows/domain/DomainFlowUtils.java index 7dfd5ff4e..f4fe2bcc3 100644 --- a/java/google/registry/flows/domain/DomainFlowUtils.java +++ b/java/google/registry/flows/domain/DomainFlowUtils.java @@ -120,6 +120,7 @@ import java.util.List; import java.util.Map.Entry; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.Nullable; import org.joda.money.CurrencyUnit; import org.joda.money.Money; @@ -724,7 +725,7 @@ public class DomainFlowUtils { if (types.size() == 0) { throw new FeeDescriptionParseException(fee.getDescription()); } else if (types.size() > 1) { - throw new FeeDescriptionMultipleMatchesException(fee.getDescription()); + throw new FeeDescriptionMultipleMatchesException(fee.getDescription(), types); } else { return types.get(0); } @@ -1354,11 +1355,13 @@ public class DomainFlowUtils { /** The fee description passed in the transform command matches multiple fee types. */ public static class FeeDescriptionMultipleMatchesException extends ParameterValuePolicyErrorException { - public FeeDescriptionMultipleMatchesException(String description) { + public FeeDescriptionMultipleMatchesException( + String description, ImmutableList types) { super( String.format( - "The fee description \"%s\" passed in the transform matches multiple fee types", - description)); + "The fee description \"%s\" passed in the transform matches multiple fee types: %s", + description, + types.stream().map(FeeType::toString).collect(Collectors.joining(", ")))); } } diff --git a/java/google/registry/model/domain/fee/BaseFee.java b/java/google/registry/model/domain/fee/BaseFee.java index 2c9483082..a581b3c7a 100644 --- a/java/google/registry/model/domain/fee/BaseFee.java +++ b/java/google/registry/model/domain/fee/BaseFee.java @@ -49,7 +49,7 @@ public abstract class BaseFee extends ImmutableObject { /** Enum for the type of the fee. */ public enum FeeType { CREATE("create"), - EAP("Early Access Period, fee expires: %s"), + EAP("Early Access Period, fee expires: %s", "Early Access Period"), RENEW("renew"), RESTORE("restore"), /** @@ -65,8 +65,11 @@ public abstract class BaseFee extends ImmutableObject { private final String formatString; - FeeType(String formatString) { + private final ImmutableList extraAcceptableDescriptions; + + FeeType(String formatString, String... extraAcceptableDescriptions) { this.formatString = formatString; + this.extraAcceptableDescriptions = ImmutableList.copyOf(extraAcceptableDescriptions); } String renderDescription(Object... args) { @@ -74,7 +77,14 @@ public abstract class BaseFee extends ImmutableObject { } boolean matchFormatString(String description) { - return Ascii.toLowerCase(formatString).contains(Ascii.toLowerCase(description)); + return new ImmutableList.Builder() + .add(formatString) + .addAll(extraAcceptableDescriptions) + .build() + .stream() + .anyMatch( + expectedDescription -> + Ascii.toLowerCase(description).contains(Ascii.toLowerCase(expectedDescription))); } } diff --git a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java index c222ca42b..bd130c958 100644 --- a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java @@ -2277,12 +2277,40 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase