Add nomulus tool setter for sunrush add grace period on TLDs

This also cleans up a few miscellaneous code quality issues encountered
while adding the new setter: using a cleaner way to conditionally set field
values, documenting the format of the add grace period parameters, and
improves some code comments and formatting.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178387731
This commit is contained in:
mcilwain 2017-12-08 09:42:21 -08:00 committed by jianglai
parent 6bd0fc58de
commit 68a26f5b6e
4 changed files with 69 additions and 73 deletions

View file

@ -20,10 +20,12 @@ import static google.registry.model.registry.label.ReservedListTest.GET_NAME_FUN
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.JPY;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
import static org.joda.time.Duration.standardDays;
import static org.joda.time.Duration.standardMinutes;
import com.beust.jcommander.ParameterException;
@ -141,6 +143,17 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
assertThat(Registry.get("xn--q9jyb4c").getAddGracePeriodLength()).isEqualTo(standardMinutes(5));
}
@Test
public void testSuccess_sunrushAddGracePeriodFlag() throws Exception {
runCommandForced(
"--sunrush_add_grace_period=P13D",
"--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getSunrushAddGracePeriodLength())
.isEqualTo(standardDays(13));
}
@Test
public void testSuccess_roidSuffixWorks() throws Exception {
runCommandForced("--roid_suffix=RSUFFIX", "--dns_writers=VoidDnsWriter", "tld");
@ -296,6 +309,19 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
"xn--q9jyb4c");
}
@Test
public void testFailure_invalidSunrushAddGracePeriod() throws Exception {
Exception e = expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--sunrush_add_grace_period=5d",
"--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(e).hasMessageThat().isEqualTo("Invalid format: \"5d\"");
}
@Test
public void testFailure_invalidRedemptionGracePeriod() throws Exception {
thrown.expect(IllegalArgumentException.class, "Invalid format: \"5m\"");