Add a flag to registry_tool for EAP

Add a flag to CreateTldCommand to allow us to set the EAP fee schedule for the
registry.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125068579
This commit is contained in:
mmuller 2016-06-16 09:33:53 -07:00 committed by Ben McIlwain
parent a277e7c040
commit 4f91d03704
3 changed files with 48 additions and 3 deletions

View file

@ -171,6 +171,15 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
ImmutableSortedMap<DateTime, Money> renewBillingCostTransitions = ImmutableSortedMap<DateTime, Money> renewBillingCostTransitions =
ImmutableSortedMap.of(); ImmutableSortedMap.of();
@Parameter(
names = "--eap_fee_schedule",
converter = BillingCostTransitions.class,
validateWith = BillingCostTransitions.class,
description = "Comma-delimited list of EAP fees effective on specific dates, of the form "
+ "<time>=<money-amount>[,<time>=<money-amount>]* where each amount represents the "
+ "EAP fee for creating a new domain under the TLD.")
ImmutableSortedMap<DateTime, Money> eapFeeSchedule = ImmutableSortedMap.of();
@Nullable @Nullable
@Parameter( @Parameter(
names = "--reserved_lists", names = "--reserved_lists",
@ -271,6 +280,10 @@ abstract class CreateOrUpdateTldCommand extends MutatingCommand {
builder.setRenewBillingCostTransitions(renewBillingCostTransitions); builder.setRenewBillingCostTransitions(renewBillingCostTransitions);
} }
if (!eapFeeSchedule.isEmpty()) {
builder.setEapFeeSchedule(eapFeeSchedule);
}
if (addGracePeriod != null) { if (addGracePeriod != null) {
builder.setAddGracePeriodLength(addGracePeriod); builder.setAddGracePeriodLength(addGracePeriod);
} }

View file

@ -80,9 +80,9 @@ class CreateTldCommand extends CreateOrUpdateTldCommand {
builder.setCurrency(currency); builder.setCurrency(currency);
// If this is a non-default currency, set the EAP fee schedule to a matching currency. // If this is a non-default currency and the user hasn't specified an EAP fee schedule, set the
// TODO(b/29089413): once we have a flag for this, don't do this check if the flag is set. // EAP fee schedule to a matching currency.
if (currency != Registry.DEFAULT_CURRENCY) { if (currency != Registry.DEFAULT_CURRENCY && eapFeeSchedule.isEmpty()) {
builder.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(currency))); builder.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(currency)));
} }
} }

View file

@ -44,6 +44,8 @@ import java.io.PrintStream;
/** Unit tests for {@link CreateTldCommand}. */ /** Unit tests for {@link CreateTldCommand}. */
public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> { public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
private static final String DATETIME_FORMAT = "YYYY-MM-dd'T'HH:mm:ssZZ";
@Before @Before
public void init() { public void init() {
persistReservedList("common_abuse", "baa,FULLY_BLOCKED"); persistReservedList("common_abuse", "baa,FULLY_BLOCKED");
@ -91,6 +93,25 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
.isEqualTo(Money.of(USD, 42.42)); .isEqualTo(Money.of(USD, 42.42));
} }
@Test
public void testSuccess_eapFeeSchedule() throws Exception {
DateTime now = DateTime.now(UTC);
DateTime tomorrow = now.plusDays(1);
runCommandForced(
String.format(
"--eap_fee_schedule=\"%s=USD 0.00,%s=USD 50.00,%s=USD 10.00\"",
START_OF_TIME.toString(DATETIME_FORMAT),
now.toString(DATETIME_FORMAT),
tomorrow.toString(DATETIME_FORMAT)),
"--roid_suffix=Q9JYB4C",
"xn--q9jyb4c");
Registry registry = Registry.get("xn--q9jyb4c");
assertThat(registry.getEapFeeFor(now.minusHours(1))).isEqualTo(Money.zero(USD));
assertThat(registry.getEapFeeFor(now.plusHours(1))).isEqualTo(Money.of(USD, 50));
assertThat(registry.getEapFeeFor(now.plusDays(1).plusHours(1))).isEqualTo(Money.of(USD, 10));
}
@Test @Test
public void testSuccess_addGracePeriodFlag() throws Exception { public void testSuccess_addGracePeriodFlag() throws Exception {
runCommandForced("--add_grace_period=PT300S", "--roid_suffix=Q9JYB4C", "xn--q9jyb4c"); runCommandForced("--add_grace_period=PT300S", "--roid_suffix=Q9JYB4C", "xn--q9jyb4c");
@ -230,6 +251,17 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
"--initial_renew_billing_cost=USD -42", "--roid_suffix=Q9JYB4C", "xn--q9jyb4c"); "--initial_renew_billing_cost=USD -42", "--roid_suffix=Q9JYB4C", "xn--q9jyb4c");
} }
@Test
public void testFailure_invalidEapCurrency() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommandForced(
String.format(
"--eap_fee_schedule=\"%s=JPY 123456\"",
START_OF_TIME.toString(DATETIME_FORMAT)),
"--roid_suffix=Q9JYB4C",
"xn--q9jyb4c");
}
@Test @Test
public void testFailure_noTldName() throws Exception { public void testFailure_noTldName() throws Exception {
thrown.expect(ParameterException.class); thrown.expect(ParameterException.class);