mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 00:47:11 +02:00
Validate EAP currency in Registry build
Verify that the currency of all entries in the EAP fee schedule map matches that of the registry object itself. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=124967612
This commit is contained in:
parent
ec39f15a23
commit
5a4877805b
3 changed files with 30 additions and 8 deletions
|
@ -826,15 +826,19 @@ public class Registry extends ImmutableObject implements Buildable {
|
|||
checkArgument(
|
||||
instance.getServerStatusChangeCost().getCurrencyUnit().equals(instance.currency),
|
||||
"Server status change cost must be in the registry's currency");
|
||||
checkArgument(
|
||||
Iterables.all(
|
||||
instance.getRenewBillingCostTransitions().values(),
|
||||
new Predicate<Money>(){
|
||||
Predicate<Money> currencyCheck = new Predicate<Money>(){
|
||||
@Override
|
||||
public boolean apply(Money money) {
|
||||
return money.getCurrencyUnit().equals(instance.currency);
|
||||
}}),
|
||||
}};
|
||||
checkArgument(
|
||||
Iterables.all(
|
||||
instance.getRenewBillingCostTransitions().values(), currencyCheck),
|
||||
"Renew cost must be in the registry's currency");
|
||||
checkArgument(
|
||||
Iterables.all(
|
||||
instance.eapFeeSchedule.toValueMap().values(), currencyCheck),
|
||||
"All EAP fees must be in the registry's currency");
|
||||
checkArgumentNotNull(
|
||||
instance.pricingEngineClassName, "All registries must have a configured pricing engine");
|
||||
instance.tldStrId = tldName;
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.beust.jcommander.Parameters;
|
|||
import google.registry.model.registry.Registry;
|
||||
import google.registry.model.registry.Registry.TldState;
|
||||
|
||||
import org.joda.money.CurrencyUnit;
|
||||
import org.joda.money.Money;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -73,9 +74,17 @@ class CreateTldCommand extends CreateOrUpdateTldCommand {
|
|||
void setCommandSpecificProperties(Registry.Builder builder) {
|
||||
// Pick up the currency from the create cost. Since all costs must be in one currency, and that
|
||||
// condition is enforced by the builder, it doesn't matter which cost we choose it from.
|
||||
builder.setCurrency(createBillingCost != null
|
||||
CurrencyUnit currency = createBillingCost != null
|
||||
? createBillingCost.getCurrencyUnit()
|
||||
: Registry.DEFAULT_CURRENCY);
|
||||
: Registry.DEFAULT_CURRENCY;
|
||||
|
||||
builder.setCurrency(currency);
|
||||
|
||||
// If this is a non-default currency, set the EAP fee schedule to a matching currency.
|
||||
// TODO(b/29089413): once we have a flag for this, don't do this check if the flag is set.
|
||||
if (currency != Registry.DEFAULT_CURRENCY) {
|
||||
builder.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(currency)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -434,4 +434,13 @@ public class RegistryTest extends EntityTestCase {
|
|||
assertThat(registry.getEapFeeFor(clock.nowUtc().minusDays(2))).isEqualTo(Money.of(USD, 0));
|
||||
assertThat(registry.getEapFeeFor(clock.nowUtc().plusDays(2))).isEqualTo(Money.of(USD, 50));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_eapFee_wrongCurrency() {
|
||||
thrown.expect(
|
||||
IllegalArgumentException.class, "All EAP fees must be in the registry's currency");
|
||||
Registry.get("tld").asBuilder()
|
||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue