From 706f3b44edd79fe02f5d83e7076b7655f1ff261c Mon Sep 17 00:00:00 2001 From: nickfelt Date: Tue, 19 Apr 2016 08:29:27 -0700 Subject: [PATCH] Enforce currency consistency for server status billing cost Also adds tests for currency consistency for other costs, and cleans up some of the testing for negative currencies (since I was there). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=120231198 --- .../registry/model/registry/Registry.java | 16 +++--- .../DomainApplicationCreateFlowTest.java | 1 + .../flows/domain/DomainCreateFlowTest.java | 1 + .../flows/domain/DomainRenewFlowTest.java | 1 + .../domain/DomainRestoreRequestFlowTest.java | 1 + .../domain/DomainTransferRequestFlowTest.java | 1 + .../registry/model/registry/RegistryTest.java | 50 +++++++++++++++---- .../registry/tools/CreateTldCommandTest.java | 1 + .../registry/tools/UpdateTldCommandTest.java | 2 + 9 files changed, 59 insertions(+), 15 deletions(-) diff --git a/java/com/google/domain/registry/model/registry/Registry.java b/java/com/google/domain/registry/model/registry/Registry.java index 148b8ee11..d8d77a812 100644 --- a/java/com/google/domain/registry/model/registry/Registry.java +++ b/java/com/google/domain/registry/model/registry/Registry.java @@ -657,7 +657,7 @@ public class Registry extends BackupGroupRoot implements Buildable { } public Builder setCreateBillingCost(Money amount) { - checkArgument(amount.isPositiveOrZero(), "billing costs must be non-negative"); + checkArgument(amount.isPositiveOrZero(), "create billing cost cannot be negative"); getInstance().createBillingCost = amount; return this; } @@ -698,7 +698,7 @@ public class Registry extends BackupGroupRoot implements Buildable { } public Builder setRestoreBillingCost(Money amount) { - checkArgument(amount.isPositiveOrZero(), "billing costs must be non-negative"); + checkArgument(amount.isPositiveOrZero(), "restore billing cost cannot be negative"); getInstance().restoreBillingCost = amount; return this; } @@ -713,7 +713,7 @@ public class Registry extends BackupGroupRoot implements Buildable { */ public Builder setRenewBillingCostTransitions( ImmutableSortedMap renewCostsMap) { - checkNotNull(renewCostsMap, "Renew billing costs map cannot be null"); + checkNotNull(renewCostsMap, "renew billing costs map cannot be null"); checkArgument(Iterables.all( renewCostsMap.values(), new Predicate() { @@ -721,7 +721,7 @@ public class Registry extends BackupGroupRoot implements Buildable { public boolean apply(Money amount) { return amount.isPositiveOrZero(); }}), - "Renew billing costs cannot be negative"); + "renew billing cost cannot be negative"); getInstance().renewBillingCostTransitions = TimedTransitionProperty.fromValueMap(renewCostsMap, BillingCostTransition.class); return this; @@ -733,7 +733,8 @@ public class Registry extends BackupGroupRoot implements Buildable { } public Builder setServerStatusChangeBillingCost(Money amount) { - checkArgument(amount.isPositiveOrZero(), "billing costs must be non-negative"); + checkArgument( + amount.isPositiveOrZero(), "server status change billing cost cannot be negative"); getInstance().serverStatusChangeBillingCost = amount; return this; } @@ -785,6 +786,9 @@ public class Registry extends BackupGroupRoot implements Buildable { checkArgument( instance.getStandardRestoreCost().getCurrencyUnit().equals(instance.currency), "Restore cost must be in the registry's currency"); + checkArgument( + instance.getServerStatusChangeCost().getCurrencyUnit().equals(instance.currency), + "Server status change cost must be in the registry's currency"); checkArgument( Iterables.all( instance.getRenewBillingCostTransitions().values(), @@ -793,7 +797,7 @@ public class Registry extends BackupGroupRoot implements Buildable { public boolean apply(Money money) { return money.getCurrencyUnit().equals(instance.currency); }}), - "Renew costs must be in the registry's currency"); + "Renew cost must be in the registry's currency"); instance.tldStrId = tldName; instance.tldUnicode = Idn.toUnicode(tldName); return super.build(); diff --git a/javatests/com/google/domain/registry/flows/domain/DomainApplicationCreateFlowTest.java b/javatests/com/google/domain/registry/flows/domain/DomainApplicationCreateFlowTest.java index ef4d8871b..0ac370dda 100644 --- a/javatests/com/google/domain/registry/flows/domain/DomainApplicationCreateFlowTest.java +++ b/javatests/com/google/domain/registry/flows/domain/DomainApplicationCreateFlowTest.java @@ -1139,6 +1139,7 @@ public class DomainApplicationCreateFlowTest .setCreateBillingCost(Money.of(EUR, 13)) .setRestoreBillingCost(Money.of(EUR, 11)) .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7))) + .setServerStatusChangeBillingCost(Money.of(EUR, 19)) .build()); persistContactsAndHosts(); clock.advanceOneMilli(); diff --git a/javatests/com/google/domain/registry/flows/domain/DomainCreateFlowTest.java b/javatests/com/google/domain/registry/flows/domain/DomainCreateFlowTest.java index 86d4ded84..5b0e97852 100644 --- a/javatests/com/google/domain/registry/flows/domain/DomainCreateFlowTest.java +++ b/javatests/com/google/domain/registry/flows/domain/DomainCreateFlowTest.java @@ -558,6 +558,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase { "--create_billing_cost=\"JPY 12345\"", "--restore_billing_cost=\"JPY 67890\"", "--initial_renew_billing_cost=\"JPY 101112\"", + "--server_status_change_cost=\"JPY 97865\"", "--roid_suffix=Q9JYB4C", "xn--q9jyb4c"); Registry registry = Registry.get("xn--q9jyb4c"); diff --git a/javatests/com/google/domain/registry/tools/UpdateTldCommandTest.java b/javatests/com/google/domain/registry/tools/UpdateTldCommandTest.java index b532ab6e5..ebe5b6fa5 100644 --- a/javatests/com/google/domain/registry/tools/UpdateTldCommandTest.java +++ b/javatests/com/google/domain/registry/tools/UpdateTldCommandTest.java @@ -215,11 +215,13 @@ public class UpdateTldCommandTest extends CommandTestCase { .setRestoreBillingCost(Money.ofMajor(JPY, 1)) .setRenewBillingCostTransitions( ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 1))) + .setServerStatusChangeBillingCost(Money.ofMajor(JPY, 1)) .build()); runCommandForced( "--create_billing_cost=\"JPY 12345\"", "--restore_billing_cost=\"JPY 67890\"", "--renew_billing_cost_transitions=\"0=JPY 101112\"", + "--server_status_change_cost=\"JPY 97865\"", "xn--q9jyb4c"); assertThat(Registry.get("xn--q9jyb4c").getStandardCreateCost()) .isEqualTo(Money.ofMajor(JPY, 12345));