From 91f6c7006ebf4b6c041658d7ef729ec642bdfd61 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Tue, 31 May 2016 10:47:02 -0700 Subject: [PATCH] Add additional return values to PricingEngine interface ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=123658519 --- .../flows/domain/BaseDomainCreateFlow.java | 2 +- .../flows/domain/DomainAllocateFlow.java | 3 +- .../domain/DomainApplicationCreateFlow.java | 2 +- .../flows/domain/DomainCheckFlow.java | 6 +- .../flows/domain/DomainCreateFlow.java | 2 +- .../flows/domain/DomainDeleteFlow.java | 2 +- .../flows/domain/DomainFlowUtils.java | 34 ++----- .../registry/flows/domain/DomainInfoFlow.java | 2 +- .../flows/domain/DomainRenewFlow.java | 4 +- .../domain/DomainRestoreRequestFlow.java | 4 +- .../domain/DomainTransferApproveFlow.java | 26 +++--- .../domain/DomainTransferRequestFlow.java | 4 +- .../registry/model/pricing/PricingEngine.java | 70 ++++++++++++-- .../StaticPremiumListPricingEngine.java | 38 +++++--- .../registry/pricing/PricingEngineProxy.java | 48 +++------- .../tools/CreateAnchorTenantCommand.java | 4 +- .../google/registry/util/DomainNameUtils.java | 23 +++-- .../flows/domain/DomainCreateFlowTest.java | 4 +- .../domain/DomainTransferFlowTestCase.java | 1 - .../pricing/PricingEngineProxyTest.java | 93 +++++++------------ .../registry/testing/DatastoreHelper.java | 10 +- 21 files changed, 191 insertions(+), 191 deletions(-) diff --git a/java/google/registry/flows/domain/BaseDomainCreateFlow.java b/java/google/registry/flows/domain/BaseDomainCreateFlow.java index 2880a6be1..2f706d9d7 100644 --- a/java/google/registry/flows/domain/BaseDomainCreateFlow.java +++ b/java/google/registry/flows/domain/BaseDomainCreateFlow.java @@ -181,7 +181,7 @@ public abstract class BaseDomainCreateFlow contacts) @@ -388,7 +385,7 @@ public class DomainFlowUtils { */ static void verifyPremiumNameIsNotBlocked( String domainName, DateTime priceTime, String clientIdentifier) throws EppException { - if (isPremiumName(domainName, priceTime, clientIdentifier)) { + if (getPricesForDomainName(domainName, priceTime).isPremium()) { // NB: The load of the Registar object is transactionless, which means that it should hit // memcache most of the time. if (Registrar.loadByClientId(clientIdentifier).getBlockPremiumNames()) { @@ -563,15 +560,12 @@ public class DomainFlowUtils { BaseFeeResponse.Builder builder, String domainName, String tld, - String clientIdentifier, DateTime now) throws EppException { InternetDomainName domain = InternetDomainName.from(domainName); FeeCommandDescriptor feeCommand = feeRequest.getCommand(); Registry registry = Registry.get(tld); int years = verifyUnitIsYears(feeRequest.getPeriod()).getValue(); boolean isSunrise = registry.getTldState(now).equals(TldState.SUNRISE); - boolean isNameCollisionInSunrise = - isSunrise && getReservationType(domain) == ReservationType.NAME_COLLISION; if (feeCommand.getPhase() != null || feeCommand.getSubphase() != null) { throw new FeeChecksDontSupportPhasesException(); @@ -581,14 +575,13 @@ public class DomainFlowUtils { throw new CurrencyUnitMismatchException(); } + DomainPrices prices = getPricesForDomainName(domainName, now); builder .setCommand(feeCommand) .setCurrency(registry.getCurrency()) .setPeriod(feeRequest.getPeriod()) // Choose from four classes: premium, premium-collision, collision, or null (standard case). - .setClass(emptyToNull(Joiner.on('-').skipNulls().join( - isPremiumName(domainName, now, clientIdentifier) ? "premium" : null, - isNameCollisionInSunrise ? "collision" : null))); + .setClass(prices.getFeeClass().orNull()); switch (feeCommand.getCommand()) { case UNKNOWN: @@ -598,9 +591,7 @@ public class DomainFlowUtils { builder.setClass("reserved"); // Override whatever class we've set above. } else { builder.setFee( - Fee.create( - getDomainCreateCost(domainName, now, clientIdentifier, years).getAmount(), - "create")); + Fee.create(prices.getCreateCost().multipliedBy(years).getAmount(), "create")); } break; case RESTORE: @@ -609,17 +600,12 @@ public class DomainFlowUtils { } // Restores have a "renew" and a "restore" fee. builder.setFee( - Fee.create( - getDomainRenewCost(domainName, now, clientIdentifier, years).getAmount(), - "renew"), + Fee.create(prices.getRenewCost().multipliedBy(years).getAmount(), "renew"), Fee.create(registry.getStandardRestoreCost().getAmount(), "restore")); break; default: // Anything else (transfer|renew) will have a "renew" fee. - builder.setFee( - Fee.create( - getDomainRenewCost(domainName, now, clientIdentifier, years).getAmount(), - "renew")); + builder.setFee(Fee.create(prices.getRenewCost().multipliedBy(years).getAmount(), "renew")); } } @@ -627,14 +613,13 @@ public class DomainFlowUtils { String domainName, String tld, DateTime priceTime, - String clientIdentifier, final BaseFeeCommand feeCommand, Money cost, Money... otherCosts) throws EppException { Registry registry = Registry.get(tld); if (registry.getPremiumPriceAckRequired() - && isPremiumName(domainName, priceTime, clientIdentifier) + && getPricesForDomainName(domainName, priceTime).isPremium() && feeCommand == null) { throw new FeesRequiredForPremiumNameException(); } @@ -1021,4 +1006,3 @@ public class DomainFlowUtils { } } } - diff --git a/java/google/registry/flows/domain/DomainInfoFlow.java b/java/google/registry/flows/domain/DomainInfoFlow.java index a6db9958f..10556a1b7 100644 --- a/java/google/registry/flows/domain/DomainInfoFlow.java +++ b/java/google/registry/flows/domain/DomainInfoFlow.java @@ -95,7 +95,7 @@ public class DomainInfoFlow extends BaseDomainInfoFlow if (feeInfo != null) { // Fee check was requested. FeeInfoResponseExtension.Builder builder = new FeeInfoResponseExtension.Builder(); handleFeeRequest( - feeInfo, builder, getTargetId(), existingResource.getTld(), getClientId(), now); + feeInfo, builder, getTargetId(), existingResource.getTld(), now); extensions.add(builder.build()); } if (!registrationTypes.isEmpty()) { diff --git a/java/google/registry/flows/domain/DomainRenewFlow.java b/java/google/registry/flows/domain/DomainRenewFlow.java index bcf46e02c..b8d75e0ba 100644 --- a/java/google/registry/flows/domain/DomainRenewFlow.java +++ b/java/google/registry/flows/domain/DomainRenewFlow.java @@ -110,9 +110,9 @@ public class DomainRenewFlow extends OwnedResourceMutateFlowNote that fullyQualifiedDomainName must not include any subdomains. It should be a single - * level above the TLD (which may be multi-part). + *

Note that the fullyQualifiedDomainName must only contain a single part left of the TLD, i.e. + * subdomains are not allowed, but multi-part TLDs are. */ - public Optional getPremiumPrice( - String fullyQualifiedDomainName, DateTime priceTime, String clientIdentifier); + public DomainPrices getDomainPrices(String fullyQualifiedDomainName, DateTime priceTime); + + /** + * A class containing information on prices for a specific domain name. + * + *

Any implementation of PricingEngine is responsible for determining all of these. + */ + public static class DomainPrices { + + private boolean isPremium; + // TODO(b/26901539): Refactor return values to support an arbitrary list of costs for each of + // create, renew, restore, and transfer. + private Money createCost; + private Money renewCost; + private Optional oneTimeFee; + private Optional feeClass; + + static DomainPrices create( + boolean isPremium, + Money createCost, + Money renewCost, + Optional oneTimeFee, + Optional feeClass) { + DomainPrices instance = new DomainPrices(); + instance.isPremium = isPremium; + instance.createCost = createCost; + instance.renewCost = renewCost; + instance.oneTimeFee = oneTimeFee; + instance.feeClass = feeClass; + return instance; + } + + /** Returns whether the domain is premium. */ + public boolean isPremium() { + return isPremium; + } + + /** Returns the cost to create the domain. */ + public Money getCreateCost() { + return createCost; + } + + /** Returns the cost to renew the domain. */ + public Money getRenewCost() { + return renewCost; + } + + /** + * Returns the one time fee to register a domain if there is one. + * + *

This is primarily used for EAP registration fees. + */ + public Optional getOneTimeFee() { + return oneTimeFee; + } + + /** Returns the fee class of the cost (used for the Fee extension). */ + public Optional getFeeClass() { + return feeClass; + } + } } diff --git a/java/google/registry/model/pricing/StaticPremiumListPricingEngine.java b/java/google/registry/model/pricing/StaticPremiumListPricingEngine.java index 86230f765..389f95bd5 100644 --- a/java/google/registry/model/pricing/StaticPremiumListPricingEngine.java +++ b/java/google/registry/model/pricing/StaticPremiumListPricingEngine.java @@ -16,8 +16,13 @@ package google.registry.model.pricing; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import static com.google.common.base.Strings.emptyToNull; +import static google.registry.model.registry.Registry.TldState.SUNRISE; +import static google.registry.model.registry.label.ReservationType.NAME_COLLISION; +import static google.registry.model.registry.label.ReservedList.getReservation; import static google.registry.util.DomainNameUtils.getTldFromDomainName; +import com.google.common.base.Joiner; import com.google.common.base.Optional; import com.google.common.net.InternetDomainName; @@ -35,19 +40,28 @@ public final class StaticPremiumListPricingEngine implements PricingEngine { @Inject StaticPremiumListPricingEngine() {} @Override - public Optional getPremiumPrice( - String fullyQualifiedDomainName, DateTime priceTime, String clientIdentifier) { - // Note that clientIdentifier and priceTime are not used for determining premium pricing for - // static premium lists. + public DomainPrices getDomainPrices(String fullyQualifiedDomainName, DateTime priceTime) { String tld = getTldFromDomainName(fullyQualifiedDomainName); - Registry registry = Registry.get(checkNotNull(tld, "tld")); - if (registry.getPremiumList() == null) { - return Optional.absent(); - } - String listName = registry.getPremiumList().getName(); - Optional premiumList = PremiumList.get(listName); - checkState(premiumList.isPresent(), "Could not load premium list: %s", listName); String label = InternetDomainName.from(fullyQualifiedDomainName).parts().get(0); - return premiumList.get().getPremiumPrice(label); + Registry registry = Registry.get(checkNotNull(tld, "tld")); + Optional premiumPrice = Optional.absent(); + if (registry.getPremiumList() != null) { + String listName = registry.getPremiumList().getName(); + Optional premiumList = PremiumList.get(listName); + checkState(premiumList.isPresent(), "Could not load premium list: %s", listName); + premiumPrice = premiumList.get().getPremiumPrice(label); + } + boolean isNameCollisionInSunrise = + registry.getTldState(priceTime).equals(SUNRISE) + && getReservation(label, tld) == NAME_COLLISION; + String feeClass = emptyToNull(Joiner.on('-').skipNulls().join( + premiumPrice.isPresent() ? "premium" : null, + isNameCollisionInSunrise ? "collision" : null)); + return DomainPrices.create( + premiumPrice.isPresent(), + premiumPrice.or(registry.getStandardCreateCost()), + premiumPrice.or(registry.getStandardRenewCost(priceTime)), + Optional.absent(), + Optional.fromNullable(feeClass)); } } diff --git a/java/google/registry/pricing/PricingEngineProxy.java b/java/google/registry/pricing/PricingEngineProxy.java index 7972c8ff5..0ef044c6b 100644 --- a/java/google/registry/pricing/PricingEngineProxy.java +++ b/java/google/registry/pricing/PricingEngineProxy.java @@ -16,16 +16,14 @@ package google.registry.pricing; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; -import static google.registry.model.registry.Registries.assertTldExists; import static google.registry.util.DomainNameUtils.getTldFromDomainName; import com.google.common.base.Function; -import com.google.common.base.Optional; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; -import com.google.common.net.InternetDomainName; import google.registry.model.pricing.PricingEngine; +import google.registry.model.pricing.PricingEngine.DomainPrices; import google.registry.model.registry.Registry; import org.joda.money.Money; @@ -54,53 +52,29 @@ public final class PricingEngineProxy { return pricingEngine.getClass().getCanonicalName(); }}); - /** Returns true if the given domain name is on the premium price list. */ - public static boolean isPremiumName( - String domainName, DateTime priceTime, String clientIdentifier) { - return isPremiumName(InternetDomainName.from(domainName), priceTime, clientIdentifier); - } - - /** Returns true if the given domain name is on the premium price list. */ - public static boolean isPremiumName( - InternetDomainName domainName, DateTime priceTime, String clientIdentifier) { - return getPremiumPriceForDomainName(domainName, priceTime, clientIdentifier).isPresent(); - } - /** Returns the billing cost for registering the specified domain name for this many years. */ - public static Money getDomainCreateCost( - String domainName, DateTime priceTime, String clientIdentifier, int years) { + public static Money getDomainCreateCost(String domainName, DateTime priceTime, int years) { checkArgument(years > 0, "Number of years must be positive"); - Optional annualCost = - getPremiumPriceForDomainName( - InternetDomainName.from(domainName), priceTime, clientIdentifier); - return annualCost - .or(Registry.get(getTldFromDomainName(domainName)).getStandardCreateCost()) - .multipliedBy(years); + return getPricesForDomainName(domainName, priceTime).getCreateCost().multipliedBy(years); } /** Returns the billing cost for renewing the specified domain name for this many years. */ - public static Money getDomainRenewCost( - String domainName, DateTime priceTime, String clientIdentifier, int years) { + public static Money getDomainRenewCost(String domainName, DateTime priceTime, int years) { checkArgument(years > 0, "Number of years must be positive"); - Optional annualCost = - getPremiumPriceForDomainName( - InternetDomainName.from(domainName), priceTime, clientIdentifier); - return annualCost - .or(Registry.get(getTldFromDomainName(domainName)).getStandardRenewCost(priceTime)) - .multipliedBy(years); + return getPricesForDomainName(domainName, priceTime).getRenewCost().multipliedBy(years); } /** - * Returns whether the given domain name is premium by dispatching to the appropriate - * {@link PricingEngine} based on what is configured for the TLD that the domain is under. + * Returns the full {@link DomainPrices} details for the given domain name by dispatching to the + * appropriate {@link PricingEngine} based on what is configured for the TLD that the domain is + * under. */ - private static Optional getPremiumPriceForDomainName( - InternetDomainName domainName, DateTime priceTime, String clientIdentifier) { - String tld = assertTldExists(getTldFromDomainName(domainName)); + public static DomainPrices getPricesForDomainName(String domainName, DateTime priceTime) { + String tld = getTldFromDomainName(domainName); String clazz = Registry.get(tld).getPricingEngineClassName(); PricingEngine engine = pricingEngines.get(clazz); checkState(engine != null, "Could not load pricing engine %s for TLD %s", clazz, tld); - return engine.getPremiumPrice(domainName.toString(), priceTime, clientIdentifier); + return engine.getDomainPrices(domainName, priceTime); } private PricingEngineProxy() {} diff --git a/java/google/registry/tools/CreateAnchorTenantCommand.java b/java/google/registry/tools/CreateAnchorTenantCommand.java index 86a7271a8..dba63ca9b 100644 --- a/java/google/registry/tools/CreateAnchorTenantCommand.java +++ b/java/google/registry/tools/CreateAnchorTenantCommand.java @@ -88,9 +88,7 @@ final class CreateAnchorTenantCommand extends MutatingEppToolCommand implements Money cost = null; if (fee) { - cost = - getDomainCreateCost( - domainName, DateTime.now(UTC), clientIdentifier, DEFAULT_ANCHOR_TENANT_PERIOD_YEARS); + cost = getDomainCreateCost(domainName, DateTime.now(UTC), DEFAULT_ANCHOR_TENANT_PERIOD_YEARS); } setSoyTemplate(CreateAnchorTenantSoyInfo.getInstance(), diff --git a/java/google/registry/util/DomainNameUtils.java b/java/google/registry/util/DomainNameUtils.java index 02017a75c..3b81c552d 100644 --- a/java/google/registry/util/DomainNameUtils.java +++ b/java/google/registry/util/DomainNameUtils.java @@ -43,7 +43,10 @@ public final class DomainNameUtils { } /** - * Returns the canonicalized TLD part of a valid domain name by stripping off the leftmost part. + * Returns the canonicalized TLD part of a valid fully-qualified domain name by stripping off the + * leftmost part. + * + *

This method should not be called for subdomains. * *

This function is compatible with multi-part tlds, e.g. {@code co.uk}. This function will * also work on domains for which the registry is not authoritative. If you are certain that the @@ -51,28 +54,28 @@ public final class DomainNameUtils { * {@link google.registry.model.registry.Registries#findTldForName(InternetDomainName) * Registries#findTldForName}, which will work on hostnames in addition to domains. * - * @param fullyQualifiedDomainName must be a puny-coded domain name (not a subdomain or Unicode) + * @param fullyQualifiedDomainName must be a punycode SLD (not a host or unicode) * @throws IllegalArgumentException if there is no TLD */ public static String getTldFromDomainName(String fullyQualifiedDomainName) { checkArgument( !Strings.isNullOrEmpty(fullyQualifiedDomainName), - "fullyQualifiedDomainName cannot be null or empty"); + "secondLevelDomainName cannot be null or empty"); return getTldFromDomainName(InternetDomainName.from(fullyQualifiedDomainName)); } /** - * Returns the canonicalized TLD part of a valid domain name by stripping off the leftmost part. + * Returns the canonicalized TLD part of a valid fully-qualified domain name by stripping off the + * leftmost part. * - *

This function is compatible with multi-part TLDs and must not be called with subdomains. + *

This function is compatible with multi-part TLDs and should not be called with subdomains. * * @throws IllegalArgumentException if there is no TLD */ - public static String getTldFromDomainName(InternetDomainName fullyQualifiedDomainName) { - checkArgumentNotNull(fullyQualifiedDomainName); - checkArgument( - fullyQualifiedDomainName.hasParent(), "fullyQualifiedDomainName does not have a TLD"); - return fullyQualifiedDomainName.parent().toString(); + public static String getTldFromDomainName(InternetDomainName domainName) { + checkArgumentNotNull(domainName); + checkArgument(domainName.hasParent(), "secondLevelDomainName does not have a TLD"); + return domainName.parent().toString(); } private DomainNameUtils() {} diff --git a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java index 2ad1166af..00d07f3c3 100644 --- a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java @@ -16,7 +16,7 @@ package google.registry.flows.domain; import static com.google.common.io.BaseEncoding.base16; import static com.google.common.truth.Truth.assertThat; -import static google.registry.pricing.PricingEngineProxy.isPremiumName; +import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName; import static google.registry.testing.DatastoreHelper.assertBillingEvents; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.deleteTld; @@ -180,7 +180,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase return createBillingEventForTransfer( domain, historyEntry, - "NewRegistrar", TRANSFER_REQUEST_TIME, TRANSFER_EXPIRATION_TIME, EXTENDED_REGISTRATION_YEARS); diff --git a/javatests/google/registry/pricing/PricingEngineProxyTest.java b/javatests/google/registry/pricing/PricingEngineProxyTest.java index 4b3a91b22..caa68edc3 100644 --- a/javatests/google/registry/pricing/PricingEngineProxyTest.java +++ b/javatests/google/registry/pricing/PricingEngineProxyTest.java @@ -17,7 +17,7 @@ package google.registry.pricing; import static com.google.common.truth.Truth.assertThat; import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost; import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost; -import static google.registry.pricing.PricingEngineProxy.isPremiumName; +import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistResource; @@ -26,6 +26,7 @@ import static org.joda.money.CurrencyUnit.USD; import com.google.common.collect.ImmutableSortedMap; +import google.registry.model.pricing.PricingEngine; import google.registry.model.registry.Registry; import google.registry.model.registry.label.PremiumList; import google.registry.testing.AppEngineRule; @@ -68,34 +69,34 @@ public class PricingEngineProxyTest { @Test public void test_getDomainCreateCost_multipleYears() { - assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 1)) + assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), 1)) .isEqualTo(Money.parse("USD 13")); - assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 5)) + assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), 5)) .isEqualTo(Money.parse("USD 65")); - assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 1)) + assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), 1)) .isEqualTo(Money.parse("USD 20.50")); - assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 3)) + assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), 3)) .isEqualTo(Money.parse("USD 61.50")); } @Test public void test_getDomainRenewCost_multipleYears() { - assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 1)) + assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), 1)) .isEqualTo(Money.parse("USD 11")); - assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 5)) + assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), 5)) .isEqualTo(Money.parse("USD 55")); - assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 1)) + assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), 1)) .isEqualTo(Money.parse("USD 20.50")); - assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 3)) + assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), 3)) .isEqualTo(Money.parse("USD 61.50")); } @Test public void testIsPremiumDomain() throws Exception { createTld("example"); - assertThat(isPremiumName("poor.example", clock.nowUtc(), "TheRegistrar")).isFalse(); - assertThat(isPremiumName("rich.example", clock.nowUtc(), "TheRegistrar")).isTrue(); - assertThat(isPremiumName("richer.example", clock.nowUtc(), "TheRegistrar")).isTrue(); + assertThat(getPricesForDomainName("poor.example", clock.nowUtc()).isPremium()).isFalse(); + assertThat(getPricesForDomainName("rich.example", clock.nowUtc()).isPremium()).isTrue(); + assertThat(getPricesForDomainName("richer.example", clock.nowUtc()).isPremium()).isTrue(); } @Test @@ -103,13 +104,13 @@ public class PricingEngineProxyTest { // The example tld has a premium price for "rich". createTld("example"); // The default value of 17 is set in createTld(). - assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), "TheRegistrar", 1)) + assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), 1)) .isEqualTo(Money.of(USD, 13)); - assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), "TheRegistrar", 2)) + assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), 2)) .isEqualTo(Money.of(USD, 26)); - assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), "TheRegistrar", 1)) + assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), 1)) .isEqualTo(Money.of(USD, 100)); - assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), "TheRegistrar", 2)) + assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), 2)) .isEqualTo(Money.of(USD, 200)); } @@ -124,60 +125,36 @@ public class PricingEngineProxyTest { ImmutableSortedMap.of( START_OF_TIME, Money.of(USD, 8), clock.nowUtc(), Money.of(USD, 10))) .build()); - assertThat(getDomainRenewCost("poor.example", START_OF_TIME, "TheRegistrar", 1)) + assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 1)) .isEqualTo(Money.of(USD, 8)); - assertThat(getDomainRenewCost("poor.example", START_OF_TIME, "TheRegistrar", 2)) + assertThat(getDomainRenewCost("poor.example", START_OF_TIME, 2)) .isEqualTo(Money.of(USD, 16)); - assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), "TheRegistrar", 1)) + assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 1)) .isEqualTo(Money.of(USD, 10)); - assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), "TheRegistrar", 2)) + assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), 2)) .isEqualTo(Money.of(USD, 20)); - assertThat(getDomainRenewCost("rich.example", START_OF_TIME, "TheRegistrar", 1)) + assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 1)) .isEqualTo(Money.of(USD, 100)); - assertThat(getDomainRenewCost("rich.example", START_OF_TIME, "TheRegistrar", 2)) + assertThat(getDomainRenewCost("rich.example", START_OF_TIME, 2)) .isEqualTo(Money.of(USD, 200)); - assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), "TheRegistrar", 1)) + assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 1)) .isEqualTo(Money.of(USD, 100)); - assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), "TheRegistrar", 2)) + assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), 2)) .isEqualTo(Money.of(USD, 200)); } @Test - public void testFailure_isPremiumNameForSldNotUnderTld() { - thrown.expect(IllegalArgumentException.class); - isPremiumName("test.example", clock.nowUtc(), "TheRegistrar"); - } - - @Test - public void testFailure_isPremiumNameForSldSubdomain() throws Exception { + public void testFailure_cantLoadPricingEngine() throws Exception { createTld("example"); - thrown.expect(IllegalArgumentException.class); - isPremiumName("rich.sld.example", clock.nowUtc(), "TheRegistrar"); + persistResource( + Registry.get("example").asBuilder().setPricingEngineClass(FakePricingEngine.class).build()); + thrown.expect( + IllegalStateException.class, + String.format( + "Could not load pricing engine %s for TLD example", + FakePricingEngine.class.getCanonicalName())); + getDomainCreateCost("bad.example", clock.nowUtc(), 1); } - @Test - public void testFailure_getCreateCostForSldNotUnderTld() { - thrown.expect(IllegalArgumentException.class); - getDomainCreateCost("test.example", clock.nowUtc(), "TheRegistrar", 1); - } - - @Test - public void testFailure_getCreateCostForSldSubdomain() throws Exception { - createTld("example"); - thrown.expect(IllegalArgumentException.class); - getDomainCreateCost("rich.sld.example", clock.nowUtc(), "TheRegistrar", 1); - } - - @Test - public void testFailure_getRenewCostForSldNotUnderTld() { - thrown.expect(IllegalArgumentException.class); - getDomainRenewCost("test.example", clock.nowUtc(), "TheRegistrar", 1); - } - - @Test - public void testFailure_getRenewCostForSldSubdomain() throws Exception { - createTld("example"); - thrown.expect(IllegalArgumentException.class); - getDomainRenewCost("rich.sld.example", clock.nowUtc(), "TheRegistrar", 1); - } + private abstract static class FakePricingEngine implements PricingEngine {} } diff --git a/javatests/google/registry/testing/DatastoreHelper.java b/javatests/google/registry/testing/DatastoreHelper.java index 3634a3359..e2214f7ba 100644 --- a/javatests/google/registry/testing/DatastoreHelper.java +++ b/javatests/google/registry/testing/DatastoreHelper.java @@ -428,7 +428,6 @@ public class DatastoreHelper { public static BillingEvent.OneTime createBillingEventForTransfer( DomainResource domain, HistoryEntry historyEntry, - String gainingClientId, DateTime costLookupTime, DateTime eventTime, Integer extendedRegistrationYears) { @@ -440,11 +439,9 @@ public class DatastoreHelper { eventTime.plus(Registry.get(domain.getTld()).getTransferGracePeriodLength())) .setClientId("NewRegistrar") .setPeriodYears(extendedRegistrationYears) - .setCost(getDomainRenewCost( - domain.getFullyQualifiedDomainName(), - costLookupTime, - gainingClientId, - extendedRegistrationYears)) + .setCost( + getDomainRenewCost( + domain.getFullyQualifiedDomainName(), costLookupTime, extendedRegistrationYears)) .setParent(historyEntry) .build(); } @@ -505,7 +502,6 @@ public class DatastoreHelper { BillingEvent.OneTime transferBillingEvent = persistResource(createBillingEventForTransfer( domain, historyEntryDomainTransfer, - "NewRegistrar", requestTime, expirationTime, extendedRegistrationYears));