mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Refactor Fee class to support EAP fee
Currently EapFee is a separate class that has no inheritance from either BaseFee and Fee. With this CL its functionality is merged into the Fee class and the type of the fee can be identified by the FeeType enum in the Fee class. Future custom fees can follow the same pattern. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133627570
This commit is contained in:
parent
0518f63aad
commit
77571e2063
9 changed files with 121 additions and 131 deletions
|
@ -15,7 +15,6 @@
|
||||||
package google.registry.flows.domain;
|
package google.registry.flows.domain;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
|
||||||
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
import static google.registry.model.EppResourceUtils.loadByUniqueId;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName;
|
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName;
|
||||||
|
@ -34,7 +33,6 @@ import google.registry.model.domain.LrpToken;
|
||||||
import google.registry.model.domain.fee.BaseFee;
|
import google.registry.model.domain.fee.BaseFee;
|
||||||
import google.registry.model.domain.fee.BaseFee.FeeType;
|
import google.registry.model.domain.fee.BaseFee.FeeType;
|
||||||
import google.registry.model.domain.fee.Credit;
|
import google.registry.model.domain.fee.Credit;
|
||||||
import google.registry.model.domain.fee.EapFee;
|
|
||||||
import google.registry.model.domain.fee.Fee;
|
import google.registry.model.domain.fee.Fee;
|
||||||
import google.registry.model.eppinput.EppInput;
|
import google.registry.model.eppinput.EppInput;
|
||||||
import google.registry.model.pricing.PremiumPricingEngine.DomainPrices;
|
import google.registry.model.pricing.PremiumPricingEngine.DomainPrices;
|
||||||
|
@ -160,14 +158,9 @@ public final class TldSpecificLogicProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create fees for the cost and the EAP fee, if any.
|
// Create fees for the cost and the EAP fee, if any.
|
||||||
EapFee eapFee = registry.getEapFeeFor(date);
|
Fee eapFee = registry.getEapFeeFor(date);
|
||||||
Money eapFeeCost = eapFee.getCost();
|
if (!eapFee.hasZeroCost()) {
|
||||||
checkState(eapFeeCost.getCurrencyUnit().equals(currency));
|
return new EppCommandOperations(currency, createFeeOrCredit, eapFee);
|
||||||
if (!eapFeeCost.getAmount().equals(Money.zero(currency).getAmount())) {
|
|
||||||
return new EppCommandOperations(
|
|
||||||
currency,
|
|
||||||
createFeeOrCredit,
|
|
||||||
Fee.create(eapFeeCost.getAmount(), FeeType.EAP, eapFee.getPeriod().upperEndpoint()));
|
|
||||||
} else {
|
} else {
|
||||||
return new EppCommandOperations(currency, createFeeOrCredit);
|
return new EppCommandOperations(currency, createFeeOrCredit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ package google.registry.model.domain.fee;
|
||||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
import com.google.common.collect.Range;
|
||||||
import google.registry.model.ImmutableObject;
|
import google.registry.model.ImmutableObject;
|
||||||
import google.registry.xml.PeriodAdapter;
|
import google.registry.xml.PeriodAdapter;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
@ -25,6 +26,7 @@ import javax.xml.bind.annotation.XmlEnumValue;
|
||||||
import javax.xml.bind.annotation.XmlTransient;
|
import javax.xml.bind.annotation.XmlTransient;
|
||||||
import javax.xml.bind.annotation.XmlValue;
|
import javax.xml.bind.annotation.XmlValue;
|
||||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Period;
|
import org.joda.time.Period;
|
||||||
|
|
||||||
/** Base class for the fee and credit types. */
|
/** Base class for the fee and credit types. */
|
||||||
|
@ -75,9 +77,12 @@ public abstract class BaseFee extends ImmutableObject {
|
||||||
|
|
||||||
@XmlValue
|
@XmlValue
|
||||||
BigDecimal cost;
|
BigDecimal cost;
|
||||||
|
|
||||||
@XmlTransient
|
@XmlTransient
|
||||||
FeeType type;
|
FeeType type;
|
||||||
|
|
||||||
|
@XmlTransient
|
||||||
|
Range<DateTime> validDateRange;
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
|
@ -109,11 +114,19 @@ public abstract class BaseFee extends ImmutableObject {
|
||||||
public FeeType getType() {
|
public FeeType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasValidDateRange() {
|
||||||
|
return validDateRange != null;
|
||||||
|
}
|
||||||
|
|
||||||
protected void generateDescription(Object... args) {
|
protected void generateDescription(Object... args) {
|
||||||
checkState(type != null);
|
checkState(type != null);
|
||||||
description = type.renderDescription(args);
|
description = type.renderDescription(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasZeroCost() {
|
||||||
|
return cost.signum() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasDefaultAttributes() {
|
public boolean hasDefaultAttributes() {
|
||||||
return getGracePeriod().equals(Period.ZERO)
|
return getGracePeriod().equals(Period.ZERO)
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package google.registry.model.domain.fee;
|
|
||||||
|
|
||||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
|
||||||
|
|
||||||
import com.google.common.collect.Range;
|
|
||||||
import org.joda.money.Money;
|
|
||||||
import org.joda.time.DateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An object representing an EAP fee (as a {@link Money}) along with the interval for which the
|
|
||||||
* fee applies.
|
|
||||||
*/
|
|
||||||
public class EapFee {
|
|
||||||
|
|
||||||
/** The EAP fee (as applied on top of the domain registration cost). */
|
|
||||||
Money cost;
|
|
||||||
|
|
||||||
/** The time period for which the fee applies. */
|
|
||||||
Range<DateTime> period;
|
|
||||||
|
|
||||||
public Money getCost() {
|
|
||||||
return cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Range<DateTime> getPeriod() {
|
|
||||||
return period;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static EapFee create(Money cost, Range<DateTime> period) {
|
|
||||||
EapFee instance = new EapFee();
|
|
||||||
instance.cost = checkArgumentNotNull(cost, "EAP fee cost cannot be null.");
|
|
||||||
instance.period = checkArgumentNotNull(period, "EAP fee period cannot be null.");
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Range;
|
||||||
import google.registry.model.domain.fee06.FeeCheckCommandExtensionV06;
|
import google.registry.model.domain.fee06.FeeCheckCommandExtensionV06;
|
||||||
import google.registry.model.domain.fee06.FeeCreateCommandExtensionV06;
|
import google.registry.model.domain.fee06.FeeCreateCommandExtensionV06;
|
||||||
import google.registry.model.domain.fee06.FeeRenewCommandExtensionV06;
|
import google.registry.model.domain.fee06.FeeRenewCommandExtensionV06;
|
||||||
|
@ -36,6 +37,7 @@ import google.registry.model.domain.fee12.FeeTransferCommandExtensionV12;
|
||||||
import google.registry.model.domain.fee12.FeeUpdateCommandExtensionV12;
|
import google.registry.model.domain.fee12.FeeUpdateCommandExtensionV12;
|
||||||
import google.registry.model.eppcommon.ProtocolDefinition.ServiceExtension;
|
import google.registry.model.eppcommon.ProtocolDefinition.ServiceExtension;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fee, in currency units specified elsewhere in the xml, with type of the fee an optional fee
|
* A fee, in currency units specified elsewhere in the xml, with type of the fee an optional fee
|
||||||
|
@ -51,6 +53,13 @@ public class Fee extends BaseFee {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Fee create(
|
||||||
|
BigDecimal cost, FeeType type, Range<DateTime> validDateRange, Object... descriptionArgs) {
|
||||||
|
Fee instance = create(cost, type, descriptionArgs);
|
||||||
|
instance.validDateRange = validDateRange;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
public static final ImmutableList<
|
public static final ImmutableList<
|
||||||
Class<? extends FeeCheckCommandExtension<
|
Class<? extends FeeCheckCommandExtension<
|
||||||
? extends FeeCheckCommandExtensionItem, ? extends FeeCheckResponseExtension<?>>>>
|
? extends FeeCheckCommandExtensionItem, ? extends FeeCheckResponseExtension<?>>>>
|
||||||
|
@ -91,10 +100,9 @@ public class Fee extends BaseFee {
|
||||||
FeeUpdateCommandExtensionV11.class,
|
FeeUpdateCommandExtensionV11.class,
|
||||||
FeeUpdateCommandExtensionV06.class);
|
FeeUpdateCommandExtensionV06.class);
|
||||||
|
|
||||||
public static final ImmutableSet<String>
|
public static final ImmutableSet<String> FEE_EXTENSION_URIS =
|
||||||
FEE_EXTENSION_URIS =
|
ImmutableSet.<String>of(
|
||||||
ImmutableSet.<String>of(
|
ServiceExtension.FEE_0_12.getUri(),
|
||||||
ServiceExtension.FEE_0_12.getUri(),
|
ServiceExtension.FEE_0_11.getUri(),
|
||||||
ServiceExtension.FEE_0_11.getUri(),
|
ServiceExtension.FEE_0_6.getUri());
|
||||||
ServiceExtension.FEE_0_6.getUri());
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,8 @@ import google.registry.model.ImmutableObject;
|
||||||
import google.registry.model.common.EntityGroupRoot;
|
import google.registry.model.common.EntityGroupRoot;
|
||||||
import google.registry.model.common.TimedTransitionProperty;
|
import google.registry.model.common.TimedTransitionProperty;
|
||||||
import google.registry.model.common.TimedTransitionProperty.TimedTransition;
|
import google.registry.model.common.TimedTransitionProperty.TimedTransition;
|
||||||
import google.registry.model.domain.fee.EapFee;
|
import google.registry.model.domain.fee.BaseFee.FeeType;
|
||||||
|
import google.registry.model.domain.fee.Fee;
|
||||||
import google.registry.model.registry.label.PremiumList;
|
import google.registry.model.registry.label.PremiumList;
|
||||||
import google.registry.model.registry.label.ReservedList;
|
import google.registry.model.registry.label.ReservedList;
|
||||||
import google.registry.util.Idn;
|
import google.registry.util.Idn;
|
||||||
|
@ -518,15 +519,19 @@ public class Registry extends ImmutableObject implements Buildable {
|
||||||
/**
|
/**
|
||||||
* Returns the EAP fee for the registry at the given time.
|
* Returns the EAP fee for the registry at the given time.
|
||||||
*/
|
*/
|
||||||
public EapFee getEapFeeFor(DateTime now) {
|
public Fee getEapFeeFor(DateTime now) {
|
||||||
ImmutableSortedMap<DateTime, Money> valueMap = eapFeeSchedule.toValueMap();
|
ImmutableSortedMap<DateTime, Money> valueMap = eapFeeSchedule.toValueMap();
|
||||||
DateTime periodStart = valueMap.floorKey(now);
|
DateTime periodStart = valueMap.floorKey(now);
|
||||||
DateTime periodEnd = valueMap.ceilingKey(now);
|
DateTime periodEnd = valueMap.ceilingKey(now);
|
||||||
return EapFee.create(
|
// NOTE: assuming END_OF_TIME would never be reached...
|
||||||
eapFeeSchedule.getValueAtTime(now),
|
Range<DateTime> validPeriod = Range.closedOpen(
|
||||||
Range.closedOpen(
|
periodStart != null ? periodStart : START_OF_TIME,
|
||||||
periodStart != null ? periodStart : START_OF_TIME,
|
periodEnd != null ? periodEnd : END_OF_TIME);
|
||||||
periodEnd != null ? periodEnd : END_OF_TIME));
|
return Fee.create(
|
||||||
|
eapFeeSchedule.getValueAtTime(now).getAmount(),
|
||||||
|
FeeType.EAP,
|
||||||
|
validPeriod,
|
||||||
|
validPeriod.upperEndpoint());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLordnUsername() {
|
public String getLordnUsername() {
|
||||||
|
|
|
@ -171,7 +171,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
Money cost = getPricesForDomainName(getUniqueIdFromCommand(), clock.nowUtc()).isPremium()
|
Money cost = getPricesForDomainName(getUniqueIdFromCommand(), clock.nowUtc()).isPremium()
|
||||||
? Money.of(USD, 200)
|
? Money.of(USD, 200)
|
||||||
: Money.of(USD, 26);
|
: Money.of(USD, 26);
|
||||||
Money eapFee = Registry.get(domainTld).getEapFeeFor(clock.nowUtc()).getCost();
|
Money eapFee = Money.of(Registry.get(domainTld).getCurrency(),
|
||||||
|
Registry.get(domainTld).getEapFeeFor(clock.nowUtc()).getCost());
|
||||||
|
|
||||||
DateTime billingTime = isAnchorTenant
|
DateTime billingTime = isAnchorTenant
|
||||||
? clock.nowUtc().plus(Registry.get(domainTld).getAnchorTenantAddGracePeriodLength())
|
? clock.nowUtc().plus(Registry.get(domainTld).getAnchorTenantAddGracePeriodLength())
|
||||||
|
|
|
@ -24,6 +24,7 @@ import static org.joda.money.CurrencyUnit.USD;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSortedMap;
|
import com.google.common.collect.ImmutableSortedMap;
|
||||||
|
import com.google.common.collect.Range;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
import google.registry.flows.ResourceMutateFlow.ResourceToMutateDoesNotExistException;
|
import google.registry.flows.ResourceMutateFlow.ResourceToMutateDoesNotExistException;
|
||||||
import google.registry.model.domain.DomainResource;
|
import google.registry.model.domain.DomainResource;
|
||||||
|
@ -56,14 +57,11 @@ import org.junit.runners.JUnit4;
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class TldSpecificLogicProxyTest extends ShardableTestCase {
|
public class TldSpecificLogicProxyTest extends ShardableTestCase {
|
||||||
|
|
||||||
@Rule
|
@Rule public final InjectRule inject = new InjectRule();
|
||||||
public final InjectRule inject = new InjectRule();
|
|
||||||
|
|
||||||
@Rule
|
@Rule public final ExceptionRule thrown = new ExceptionRule();
|
||||||
public final ExceptionRule thrown = new ExceptionRule();
|
|
||||||
|
|
||||||
@Rule
|
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
||||||
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
|
|
||||||
|
|
||||||
final FakeClock clock = new FakeClock(DateTime.parse("2010-01-01T10:00:00Z"));
|
final FakeClock clock = new FakeClock(DateTime.parse("2010-01-01T10:00:00Z"));
|
||||||
|
|
||||||
|
@ -97,26 +95,36 @@ public class TldSpecificLogicProxyTest extends ShardableTestCase {
|
||||||
assertThat(createPrice.getTotalCost()).isEqualTo(basicCreateCost);
|
assertThat(createPrice.getTotalCost()).isEqualTo(basicCreateCost);
|
||||||
assertThat(createPrice.getFees()).hasSize(1);
|
assertThat(createPrice.getFees()).hasSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_eap() throws Exception {
|
public void test_eap() throws Exception {
|
||||||
TldSpecificLogicProxy.EppCommandOperations createPrice =
|
TldSpecificLogicProxy.EppCommandOperations createPrice =
|
||||||
TldSpecificLogicProxy.getCreatePrice(
|
TldSpecificLogicProxy.getCreatePrice(
|
||||||
Registry.get("eap"), "example.eap", "clientIdentifier", clock.nowUtc(), 1, null);
|
Registry.get("eap"), "example.eap", "clientIdentifier", clock.nowUtc(), 1, null);
|
||||||
|
Range<DateTime> eapValidPeriod =
|
||||||
|
Range.closedOpen(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1));
|
||||||
assertThat(createPrice.getTotalCost()).isEqualTo(basicCreateCost.plus(Money.of(USD, 100)));
|
assertThat(createPrice.getTotalCost()).isEqualTo(basicCreateCost.plus(Money.of(USD, 100)));
|
||||||
assertThat(createPrice.getCurrency()).isEqualTo(USD);
|
assertThat(createPrice.getCurrency()).isEqualTo(USD);
|
||||||
assertThat(createPrice.getFees().get(0))
|
assertThat(createPrice.getFees().get(0))
|
||||||
.isEqualTo(Fee.create(basicCreateCost.getAmount(), FeeType.CREATE));
|
.isEqualTo(Fee.create(basicCreateCost.getAmount(), FeeType.CREATE));
|
||||||
assertThat(createPrice.getFees().get(1))
|
assertThat(createPrice.getFees().get(1))
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
Fee.create(Money.of(USD, 100).getAmount(), FeeType.EAP, clock.nowUtc().plusDays(1)));
|
Fee.create(
|
||||||
|
new BigDecimal("100.00"),
|
||||||
|
FeeType.EAP,
|
||||||
|
eapValidPeriod,
|
||||||
|
clock.nowUtc().plusDays(1)));
|
||||||
assertThat(createPrice.getFees())
|
assertThat(createPrice.getFees())
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
Fee.create(basicCreateCost.getAmount(), FeeType.CREATE),
|
Fee.create(basicCreateCost.getAmount(), FeeType.CREATE),
|
||||||
Fee.create(Money.of(USD, 100).getAmount(), FeeType.EAP, clock.nowUtc().plusDays(1)))
|
Fee.create(
|
||||||
|
new BigDecimal("100.00"),
|
||||||
|
FeeType.EAP,
|
||||||
|
eapValidPeriod,
|
||||||
|
clock.nowUtc().plusDays(1)))
|
||||||
.inOrder();
|
.inOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_extraLogic_createPrice() throws Exception {
|
public void test_extraLogic_createPrice() throws Exception {
|
||||||
TldSpecificLogicProxy.EppCommandOperations price =
|
TldSpecificLogicProxy.EppCommandOperations price =
|
||||||
|
@ -128,7 +136,7 @@ public class TldSpecificLogicProxyTest extends ShardableTestCase {
|
||||||
assertThat(price.getFees().get(0).getDescription()).isEqualTo("create");
|
assertThat(price.getFees().get(0).getDescription()).isEqualTo("create");
|
||||||
assertThat(price.getCredits()).isEmpty();
|
assertThat(price.getCredits()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_extraLogic_renewPrice() throws Exception {
|
public void test_extraLogic_renewPrice() throws Exception {
|
||||||
persistActiveDomain("renew--13.test");
|
persistActiveDomain("renew--13.test");
|
||||||
|
@ -141,34 +149,40 @@ public class TldSpecificLogicProxyTest extends ShardableTestCase {
|
||||||
assertThat(price.getCredits().get(0).getCost()).isEqualTo(new BigDecimal(-13));
|
assertThat(price.getCredits().get(0).getCost()).isEqualTo(new BigDecimal(-13));
|
||||||
assertThat(price.getCredits().get(0).getDescription()).isEqualTo("renew");
|
assertThat(price.getCredits().get(0).getDescription()).isEqualTo("renew");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_extraLogic_renewPrice_noDomain() throws Exception {
|
public void test_extraLogic_renewPrice_noDomain() throws Exception {
|
||||||
thrown.expect(ResourceToMutateDoesNotExistException.class);
|
thrown.expect(ResourceToMutateDoesNotExistException.class);
|
||||||
TldSpecificLogicProxy.getRenewPrice(
|
TldSpecificLogicProxy.getRenewPrice(
|
||||||
Registry.get("test"), "renew--13.test", "clientIdentifier", clock.nowUtc(), 1, null);
|
Registry.get("test"), "renew--13.test", "clientIdentifier", clock.nowUtc(), 1, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
void persistPendingDeleteDomain(String domainName, DateTime now) throws Exception {
|
void persistPendingDeleteDomain(String domainName, DateTime now) throws Exception {
|
||||||
DomainResource domain = newDomainResource(domainName);
|
DomainResource domain = newDomainResource(domainName);
|
||||||
HistoryEntry historyEntry = persistResource(
|
HistoryEntry historyEntry =
|
||||||
new HistoryEntry.Builder()
|
persistResource(
|
||||||
.setType(HistoryEntry.Type.DOMAIN_DELETE)
|
new HistoryEntry.Builder()
|
||||||
.setParent(domain)
|
.setType(HistoryEntry.Type.DOMAIN_DELETE)
|
||||||
.build());
|
.setParent(domain)
|
||||||
domain = persistResource(domain.asBuilder()
|
.build());
|
||||||
.setRegistrationExpirationTime(now.plusYears(5).plusDays(45))
|
domain =
|
||||||
.setDeletionTime(now.plusDays(35))
|
persistResource(
|
||||||
.addGracePeriod(GracePeriod.create(
|
domain
|
||||||
GracePeriodStatus.REDEMPTION, now.plusDays(1), "foo", null))
|
.asBuilder()
|
||||||
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
|
.setRegistrationExpirationTime(now.plusYears(5).plusDays(45))
|
||||||
.setDeletePollMessage(Key.create(persistResource(
|
.setDeletionTime(now.plusDays(35))
|
||||||
new PollMessage.OneTime.Builder()
|
.addGracePeriod(
|
||||||
.setClientId("TheRegistrar")
|
GracePeriod.create(GracePeriodStatus.REDEMPTION, now.plusDays(1), "foo", null))
|
||||||
.setEventTime(now.plusDays(5))
|
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
|
||||||
.setParent(historyEntry)
|
.setDeletePollMessage(
|
||||||
.build())))
|
Key.create(
|
||||||
.build());
|
persistResource(
|
||||||
|
new PollMessage.OneTime.Builder()
|
||||||
|
.setClientId("TheRegistrar")
|
||||||
|
.setEventTime(now.plusDays(5))
|
||||||
|
.setParent(historyEntry)
|
||||||
|
.build())))
|
||||||
|
.build());
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,14 +199,14 @@ public class TldSpecificLogicProxyTest extends ShardableTestCase {
|
||||||
assertThat(price.getFees().get(1).getDescription()).isEqualTo("restore");
|
assertThat(price.getFees().get(1).getDescription()).isEqualTo("restore");
|
||||||
assertThat(price.getCredits()).isEmpty();
|
assertThat(price.getCredits()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_extraLogic_restorePrice_noDomain() throws Exception {
|
public void test_extraLogic_restorePrice_noDomain() throws Exception {
|
||||||
thrown.expect(ResourceToMutateDoesNotExistException.class);
|
thrown.expect(ResourceToMutateDoesNotExistException.class);
|
||||||
TldSpecificLogicProxy.getRestorePrice(
|
TldSpecificLogicProxy.getRestorePrice(
|
||||||
Registry.get("test"), "renew-13.test", "clientIdentifier", clock.nowUtc(), null);
|
Registry.get("test"), "renew-13.test", "clientIdentifier", clock.nowUtc(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_extraLogic_transferPrice() throws Exception {
|
public void test_extraLogic_transferPrice() throws Exception {
|
||||||
persistActiveDomain("renew-26.test");
|
persistActiveDomain("renew-26.test");
|
||||||
|
@ -205,7 +219,7 @@ public class TldSpecificLogicProxyTest extends ShardableTestCase {
|
||||||
assertThat(price.getFees().get(0).getDescription()).isEqualTo("renew");
|
assertThat(price.getFees().get(0).getDescription()).isEqualTo("renew");
|
||||||
assertThat(price.getCredits()).isEmpty();
|
assertThat(price.getCredits()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_extraLogic_updatePrice() throws Exception {
|
public void test_extraLogic_updatePrice() throws Exception {
|
||||||
persistActiveDomain("update-13.test");
|
persistActiveDomain("update-13.test");
|
||||||
|
|
|
@ -38,6 +38,7 @@ import google.registry.model.registry.Registry.TldState;
|
||||||
import google.registry.model.registry.label.PremiumList;
|
import google.registry.model.registry.label.PremiumList;
|
||||||
import google.registry.model.registry.label.ReservedList;
|
import google.registry.model.registry.label.ReservedList;
|
||||||
import google.registry.testing.ExceptionRule;
|
import google.registry.testing.ExceptionRule;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -414,7 +415,7 @@ public class RegistryTest extends EntityTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testEapFee_undefined() {
|
public void testEapFee_undefined() {
|
||||||
assertThat(Registry.get("tld").getEapFeeFor(clock.nowUtc()).getCost())
|
assertThat(Registry.get("tld").getEapFeeFor(clock.nowUtc()).getCost())
|
||||||
.isEqualTo(Money.of(USD, 0));
|
.isEqualTo(BigDecimal.ZERO.setScale(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -428,11 +429,12 @@ public class RegistryTest extends EntityTestCase {
|
||||||
a, Money.of(USD, 100),
|
a, Money.of(USD, 100),
|
||||||
b, Money.of(USD, 50))).build();
|
b, Money.of(USD, 50))).build();
|
||||||
|
|
||||||
assertThat(registry.getEapFeeFor(clock.nowUtc()).getCost()).isEqualTo(Money.of(USD, 100));
|
assertThat(registry.getEapFeeFor(clock.nowUtc()).getCost())
|
||||||
|
.isEqualTo(new BigDecimal("100.00"));
|
||||||
assertThat(registry.getEapFeeFor(clock.nowUtc().minusDays(2)).getCost())
|
assertThat(registry.getEapFeeFor(clock.nowUtc().minusDays(2)).getCost())
|
||||||
.isEqualTo(Money.of(USD, 0));
|
.isEqualTo(BigDecimal.ZERO.setScale(2));
|
||||||
assertThat(registry.getEapFeeFor(clock.nowUtc().plusDays(2)).getCost())
|
assertThat(registry.getEapFeeFor(clock.nowUtc().plusDays(2)).getCost())
|
||||||
.isEqualTo(Money.of(USD, 50));
|
.isEqualTo(new BigDecimal("50.00"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -32,6 +32,7 @@ import google.registry.model.registry.Registry;
|
||||||
import google.registry.model.registry.Registry.TldState;
|
import google.registry.model.registry.Registry.TldState;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -103,10 +104,12 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
"xn--q9jyb4c");
|
"xn--q9jyb4c");
|
||||||
|
|
||||||
Registry registry = Registry.get("xn--q9jyb4c");
|
Registry registry = Registry.get("xn--q9jyb4c");
|
||||||
assertThat(registry.getEapFeeFor(now.minusHours(1)).getCost()).isEqualTo(Money.zero(USD));
|
assertThat(registry.getEapFeeFor(now.minusHours(1)).getCost())
|
||||||
assertThat(registry.getEapFeeFor(now.plusHours(1)).getCost()).isEqualTo(Money.of(USD, 50));
|
.isEqualTo(BigDecimal.ZERO.setScale(2));
|
||||||
|
assertThat(registry.getEapFeeFor(now.plusHours(1)).getCost())
|
||||||
|
.isEqualTo(new BigDecimal("50.00"));
|
||||||
assertThat(registry.getEapFeeFor(now.plusDays(1).plusHours(1)).getCost())
|
assertThat(registry.getEapFeeFor(now.plusDays(1).plusHours(1)).getCost())
|
||||||
.isEqualTo(Money.of(USD, 10));
|
.isEqualTo(new BigDecimal("10.00"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -155,8 +158,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_createBillingCostFlag() throws Exception {
|
public void testSuccess_createBillingCostFlag() throws Exception {
|
||||||
runCommandForced(
|
runCommandForced("--create_billing_cost=\"USD 42.42\"", "--roid_suffix=Q9JYB4C", "xn--q9jyb4c");
|
||||||
"--create_billing_cost=\"USD 42.42\"", "--roid_suffix=Q9JYB4C", "xn--q9jyb4c");
|
|
||||||
assertThat(Registry.get("xn--q9jyb4c").getStandardCreateCost()).isEqualTo(Money.of(USD, 42.42));
|
assertThat(Registry.get("xn--q9jyb4c").getStandardCreateCost()).isEqualTo(Money.of(USD, 42.42));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,8 +220,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
"--initial_tld_state=SUNRISE",
|
"--initial_tld_state=SUNRISE",
|
||||||
"--roid_suffix=Q9JYB4C",
|
"--roid_suffix=Q9JYB4C",
|
||||||
"xn--q9jyb4c");
|
"xn--q9jyb4c");
|
||||||
assertThat(Registry.get("xn--q9jyb4c").getLrpTldStates())
|
assertThat(Registry.get("xn--q9jyb4c").getLrpTldStates()).containsExactly(TldState.SUNRISE);
|
||||||
.containsExactly(TldState.SUNRISE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -272,7 +273,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now.plus(1)),
|
String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now.plus(1)),
|
||||||
"--initial_tld_state=GENERAL_AVAILABILITY",
|
"--initial_tld_state=GENERAL_AVAILABILITY",
|
||||||
"xn--q9jyb4c");
|
"xn--q9jyb4c");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_negativeInitialRenewBillingCost() throws Exception {
|
public void testFailure_negativeInitialRenewBillingCost() throws Exception {
|
||||||
|
@ -286,8 +287,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
thrown.expect(IllegalArgumentException.class);
|
thrown.expect(IllegalArgumentException.class);
|
||||||
runCommandForced(
|
runCommandForced(
|
||||||
String.format(
|
String.format(
|
||||||
"--eap_fee_schedule=\"%s=JPY 123456\"",
|
"--eap_fee_schedule=\"%s=JPY 123456\"", START_OF_TIME.toString(DATETIME_FORMAT)),
|
||||||
START_OF_TIME.toString(DATETIME_FORMAT)),
|
|
||||||
"--roid_suffix=Q9JYB4C",
|
"--roid_suffix=Q9JYB4C",
|
||||||
"xn--q9jyb4c");
|
"xn--q9jyb4c");
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_setReservedListFromOtherTld() throws Exception {
|
public void testFailure_setReservedListFromOtherTld() throws Exception {
|
||||||
runFailureReservedListsTest("tld_banned",
|
runFailureReservedListsTest(
|
||||||
|
"tld_banned",
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
"The reserved list(s) tld_banned cannot be applied to the tld xn--q9jyb4c");
|
"The reserved list(s) tld_banned cannot be applied to the tld xn--q9jyb4c");
|
||||||
}
|
}
|
||||||
|
@ -363,7 +364,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_setCommonAndReservedListFromOtherTld() throws Exception {
|
public void testFailure_setCommonAndReservedListFromOtherTld() throws Exception {
|
||||||
runFailureReservedListsTest("common_abuse,tld_banned",
|
runFailureReservedListsTest(
|
||||||
|
"common_abuse,tld_banned",
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
"The reserved list(s) tld_banned cannot be applied to the tld xn--q9jyb4c");
|
"The reserved list(s) tld_banned cannot be applied to the tld xn--q9jyb4c");
|
||||||
}
|
}
|
||||||
|
@ -381,7 +383,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_setMultipleReservedListsFromOtherTld() throws Exception {
|
public void testFailure_setMultipleReservedListsFromOtherTld() throws Exception {
|
||||||
runFailureReservedListsTest("tld_banned,soy_expurgated",
|
runFailureReservedListsTest(
|
||||||
|
"tld_banned,soy_expurgated",
|
||||||
IllegalArgumentException.class,
|
IllegalArgumentException.class,
|
||||||
"The reserved list(s) tld_banned, soy_expurgated cannot be applied to the tld xn--q9jyb4c");
|
"The reserved list(s) tld_banned, soy_expurgated cannot be applied to the tld xn--q9jyb4c");
|
||||||
}
|
}
|
||||||
|
@ -393,7 +396,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_setNonExistentReservedLists() throws Exception {
|
public void testFailure_setNonExistentReservedLists() throws Exception {
|
||||||
runFailureReservedListsTest("xn--q9jyb4c_asdf,common_asdsdgh",
|
runFailureReservedListsTest(
|
||||||
|
"xn--q9jyb4c_asdf,common_asdsdgh",
|
||||||
IllegalStateException.class,
|
IllegalStateException.class,
|
||||||
"Could not find reserved list xn--q9jyb4c_asdf to add to the tld");
|
"Could not find reserved list xn--q9jyb4c_asdf to add to the tld");
|
||||||
}
|
}
|
||||||
|
@ -458,7 +462,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runReservedListsTestOverride(String reservedLists) throws Exception {
|
private void runReservedListsTestOverride(String reservedLists) throws Exception {
|
||||||
runCommandForced("--override_reserved_list_rules",
|
runCommandForced(
|
||||||
|
"--override_reserved_list_rules",
|
||||||
"--reserved_lists",
|
"--reserved_lists",
|
||||||
reservedLists,
|
reservedLists,
|
||||||
"--roid_suffix=Q9JYB4C",
|
"--roid_suffix=Q9JYB4C",
|
||||||
|
@ -466,9 +471,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runFailureReservedListsTest(
|
private void runFailureReservedListsTest(
|
||||||
String reservedLists,
|
String reservedLists, Class<? extends Exception> errorClass, String errorMsg)
|
||||||
Class<? extends Exception> errorClass,
|
throws Exception {
|
||||||
String errorMsg) throws Exception {
|
|
||||||
thrown.expect(errorClass, errorMsg);
|
thrown.expect(errorClass, errorMsg);
|
||||||
runCommandForced("--reserved_lists", reservedLists, "--roid_suffix=Q9JYB4C", "xn--q9jyb4c");
|
runCommandForced("--reserved_lists", reservedLists, "--roid_suffix=Q9JYB4C", "xn--q9jyb4c");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue