diff --git a/core/src/main/java/google/registry/tools/CreateOrUpdateRegistrarCommand.java b/core/src/main/java/google/registry/tools/CreateOrUpdateRegistrarCommand.java index dc592a5bb..f5625ca82 100644 --- a/core/src/main/java/google/registry/tools/CreateOrUpdateRegistrarCommand.java +++ b/core/src/main/java/google/registry/tools/CreateOrUpdateRegistrarCommand.java @@ -173,7 +173,8 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand { "Registrar Billing Account key-value pairs (formatted as key=value[,key=value...]), " + "where key is a currency unit (USD, JPY, etc) and value is the registrar's billing " + "account id for that currency. During update, only the pairs that need updating " - + "need to be provided.", + + "need to be provided, except when an empty string is provided, in which case the" + + "entire map is nullified.", converter = CurrencyUnitToStringMap.class, validateWith = CurrencyUnitToStringMap.class) private Map billingAccountMap; @@ -368,7 +369,9 @@ abstract class CreateOrUpdateRegistrarCommand extends MutatingCommand { Optional.ofNullable(poNumber).ifPresent(builder::setPoNumber); if (billingAccountMap != null) { LinkedHashMap newBillingAccountMap = new LinkedHashMap<>(); - if (oldRegistrar != null && oldRegistrar.getBillingAccountMap() != null) { + if (oldRegistrar != null + && oldRegistrar.getBillingAccountMap() != null + && !billingAccountMap.isEmpty()) { newBillingAccountMap.putAll(oldRegistrar.getBillingAccountMap()); } newBillingAccountMap.putAll(billingAccountMap); diff --git a/core/src/test/java/google/registry/tools/UpdateRegistrarCommandTest.java b/core/src/test/java/google/registry/tools/UpdateRegistrarCommandTest.java index b149cb6db..f30bb0f5d 100644 --- a/core/src/test/java/google/registry/tools/UpdateRegistrarCommandTest.java +++ b/core/src/test/java/google/registry/tools/UpdateRegistrarCommandTest.java @@ -25,6 +25,7 @@ import static google.registry.testing.DatabaseHelper.newRegistry; import static google.registry.testing.DatabaseHelper.persistResource; 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.junit.jupiter.api.Assertions.assertThrows; @@ -42,7 +43,6 @@ import google.registry.testing.AppEngineExtension; import google.registry.util.CidrAddressBlock; import java.math.BigDecimal; import java.util.Optional; -import org.joda.money.CurrencyUnit; import org.joda.money.Money; import org.joda.time.DateTime; import org.junit.jupiter.api.BeforeEach; @@ -368,7 +368,18 @@ class UpdateRegistrarCommandTest extends CommandTestCase assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty(); runCommand("--billing_account_map=USD=abc123,JPY=789xyz", "--force", "NewRegistrar"); assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()) - .containsExactly(CurrencyUnit.USD, "abc123", CurrencyUnit.JPY, "789xyz"); + .containsExactly(USD, "abc123", JPY, "789xyz"); + } + + @Test + void testSuccess_billingAccountMap_nullify() throws Exception { + persistResource( + loadRegistrar("NewRegistrar") + .asBuilder() + .setBillingAccountMap(ImmutableMap.of(USD, "abc123", JPY, "789xyz")) + .build()); + runCommand("--billing_account_map=\"\"", "--force", "NewRegistrar"); + assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty(); } @Test @@ -415,8 +426,7 @@ class UpdateRegistrarCommandTest extends CommandTestCase loadRegistrar("NewRegistrar").asBuilder().setBillingAccountMap(ImmutableMap.of()).build()); assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty(); runCommand("--billing_account_map=JPY=789xyz", "--allowed_tlds=foo", "--force", "NewRegistrar"); - assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()) - .containsExactly(CurrencyUnit.JPY, "789xyz"); + assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).containsExactly(JPY, "789xyz"); } @Test @@ -425,12 +435,11 @@ class UpdateRegistrarCommandTest extends CommandTestCase persistResource( loadRegistrar("NewRegistrar") .asBuilder() - .setBillingAccountMap( - ImmutableMap.of(CurrencyUnit.USD, "abc123", CurrencyUnit.JPY, "789xyz")) + .setBillingAccountMap(ImmutableMap.of(USD, "abc123", JPY, "789xyz")) .build()); runCommand("--billing_account_map=JPY=123xyz", "--allowed_tlds=foo", "--force", "NewRegistrar"); assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()) - .containsExactly(CurrencyUnit.JPY, "123xyz", CurrencyUnit.USD, "abc123"); + .containsExactly(JPY, "123xyz", USD, "abc123"); } @Test