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

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