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
This commit is contained in:
nickfelt 2016-04-19 08:29:27 -07:00 committed by Justine Tunney
parent c5d09227c5
commit 706f3b44ed
9 changed files with 59 additions and 15 deletions

View file

@ -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<DateTime, Money> 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<Money>() {
@ -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();

View file

@ -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();

View file

@ -558,6 +558,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.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();
runFlow();

View file

@ -340,6 +340,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.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());
persistDomain();
runFlow();

View file

@ -284,6 +284,7 @@ public class DomainRestoreRequestFlowTest extends
.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());
runFlow();
}

View file

@ -443,6 +443,7 @@ public class DomainTransferRequestFlowTest
.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());
doFailingTest("domain_transfer_request_fee.xml");
}

View file

@ -25,6 +25,7 @@ import static com.google.domain.registry.testing.DatastoreHelper.persistPremiumL
import static com.google.domain.registry.testing.DatastoreHelper.persistReservedList;
import static com.google.domain.registry.util.DateTimeUtils.END_OF_TIME;
import static com.google.domain.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.EUR;
import static org.joda.money.CurrencyUnit.USD;
import com.google.common.collect.ImmutableSet;
@ -399,23 +400,54 @@ public class RegistryTest extends EntityTestCase {
}
@Test
public void testFailure_badRenewBillingCostTransitionValue() {
thrown.expect(IllegalArgumentException.class);
public void testFailure_negativeRenewBillingCostTransitionValue() {
thrown.expect(IllegalArgumentException.class, "billing cost cannot be negative");
Registry.get("tld").asBuilder()
.setRenewBillingCostTransitions(ImmutableSortedMap.of(clock.nowUtc(), Money.of(USD, -42)))
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, -42)));
}
@Test
public void testFailure_negativeCreateBillingCost() {
thrown.expect(IllegalArgumentException.class, "billing cost cannot be negative");
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, -42));
}
@Test
public void testFailure_negativeRestoreBillingCost() {
thrown.expect(IllegalArgumentException.class, "billing cost cannot be negative");
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, -42));
}
@Test
public void testFailure_negativeServerStatusChangeBillingCost() {
thrown.expect(IllegalArgumentException.class, "billing cost cannot be negative");
Registry.get("tld").asBuilder().setServerStatusChangeBillingCost(Money.of(USD, -42));
}
@Test
public void testFailure_renewBillingCostTransitionValue_wrongCurrency() {
thrown.expect(IllegalArgumentException.class, "cost must be in the registry's currency");
Registry.get("tld").asBuilder()
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 42)))
.build();
}
@Test
public void testFailure_badCreateBillingCost() {
thrown.expect(IllegalArgumentException.class);
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, -42)).build();
public void testFailure_createBillingCost_wrongCurrency() {
thrown.expect(IllegalArgumentException.class, "cost must be in the registry's currency");
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(EUR, 42)).build();
}
@Test
public void testFailure_badRestoreBillingCost() {
thrown.expect(IllegalArgumentException.class);
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, -42)).build();
public void testFailure_restoreBillingCost_wrongCurrency() {
thrown.expect(IllegalArgumentException.class, "cost must be in the registry's currency");
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(EUR, 42)).build();
}
@Test
public void testFailure_serverStatusChangeBillingCost_wrongCurrency() {
thrown.expect(IllegalArgumentException.class, "cost must be in the registry's currency");
Registry.get("tld").asBuilder().setServerStatusChangeBillingCost(Money.of(EUR, 42)).build();
}
@Test

View file

@ -165,6 +165,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
"--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");

View file

@ -215,11 +215,13 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.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));