1
0
mirror of https://github.com/google/nomulus synced 2026-04-20 08:10:50 +00:00

Add a renewal cost for ATs when renewal is SPECIFIED (#2484)

Note: this is not used yet
This commit is contained in:
gbrodman
2024-07-09 14:39:48 -04:00
committed by GitHub
parent b8a6ac72dd
commit 092e3dca47
21 changed files with 3733 additions and 3467 deletions

View File

@@ -50,6 +50,7 @@ import google.registry.model.domain.fee.FeeQueryCommandExtensionItem.CommandName
import google.registry.model.reporting.HistoryEntry.HistoryEntryId;
import google.registry.persistence.VKey;
import google.registry.persistence.WithVKey;
import google.registry.persistence.converter.JodaMoneyType;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -63,6 +64,9 @@ import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Type;
import org.joda.money.Money;
import org.joda.time.DateTime;
/** An entity representing an allocation token. */
@@ -236,6 +240,12 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
@Column(name = "renewalPriceBehavior", nullable = false)
RenewalPriceBehavior renewalPriceBehavior = RenewalPriceBehavior.DEFAULT;
/** The price used for renewals iff the renewalPriceBehavior is SPECIFIED. */
@Nullable
@Type(type = JodaMoneyType.TYPE_NAME)
@Columns(columns = {@Column(name = "renewalPriceAmount"), @Column(name = "renewalPriceCurrency")})
Money renewalPrice;
@Enumerated(EnumType.STRING)
@Column(nullable = false)
RegistrationBehavior registrationBehavior = RegistrationBehavior.DEFAULT;
@@ -310,6 +320,10 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
return renewalPriceBehavior;
}
public Optional<Money> getRenewalPrice() {
return Optional.ofNullable(renewalPrice);
}
public RegistrationBehavior getRegistrationBehavior() {
return registrationBehavior;
}
@@ -377,29 +391,12 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
public AllocationToken build() {
checkArgumentNotNull(getInstance().tokenType, "Token type must be specified");
checkArgument(!Strings.isNullOrEmpty(getInstance().token), "Token must not be null or empty");
checkArgument(
!getInstance().tokenType.equals(TokenType.BULK_PRICING)
|| getInstance().renewalPriceBehavior.equals(RenewalPriceBehavior.SPECIFIED),
"Bulk tokens must have renewalPriceBehavior set to SPECIFIED");
checkArgument(
!getInstance().tokenType.equals(TokenType.BULK_PRICING)
|| ImmutableSet.of(CommandName.CREATE).equals(getInstance().allowedEppActions),
"Bulk tokens may only be valid for CREATE actions");
checkArgument(
!getInstance().tokenType.equals(TokenType.BULK_PRICING)
|| !getInstance().discountPremiums,
"Bulk tokens cannot discount premium names");
checkArgument(
getInstance().domainName == null || getInstance().tokenType.isOneTimeUse(),
"Domain name can only be specified for SINGLE_USE or REGISTER_BSA tokens");
checkArgument(
getInstance().redemptionHistoryId == null || getInstance().tokenType.isOneTimeUse(),
"Redemption history entry can only be specified for SINGLE_USE or REGISTER_BSA tokens");
checkArgument(
getInstance().tokenType != TokenType.BULK_PRICING
|| (getInstance().allowedClientIds != null
&& getInstance().allowedClientIds.size() == 1),
"BULK_PRICING tokens must have exactly one allowed client registrar");
checkArgument(
getInstance().discountFraction > 0 || !getInstance().discountPremiums,
"Discount premiums can only be specified along with a discount fraction");
@@ -425,6 +422,33 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
|| getInstance().allowedEppActions.contains(CommandName.CREATE),
"NONPREMIUM_CREATE tokens must allow for CREATE actions");
}
checkArgument(
getInstance().renewalPriceBehavior.equals(RenewalPriceBehavior.SPECIFIED)
== (getInstance().renewalPrice != null),
"renewalPrice must be specified iff renewalPriceBehavior is SPECIFIED");
if (getInstance().tokenType.equals(TokenType.BULK_PRICING)) {
checkArgument(
getInstance().discountFraction == 1.0,
"BULK_PRICING tokens must have a discountFraction of 1.0");
checkArgument(
!getInstance().shouldDiscountPremiums(),
"BULK_PRICING tokens cannot discount premium names");
checkArgument(
getInstance().renewalPriceBehavior.equals(RenewalPriceBehavior.SPECIFIED),
"BULK_PRICING tokens must have renewalPriceBehavior set to SPECIFIED");
checkArgument(
getInstance().renewalPrice.getAmount().intValue() == 0,
"BULK_PRICING tokens must have a renewal price of 0");
checkArgument(
ImmutableSet.of(CommandName.CREATE).equals(getInstance().allowedEppActions),
"BULK_PRICING tokens may only be valid for CREATE actions");
checkArgument(
getInstance().allowedClientIds != null && getInstance().allowedClientIds.size() == 1,
"BULK_PRICING tokens must have exactly one allowed client registrar");
}
if (getInstance().domainName != null) {
try {
DomainFlowUtils.validateDomainName(getInstance().domainName);
@@ -521,6 +545,11 @@ public class AllocationToken extends UpdateAutoTimestampEntity implements Builda
return this;
}
public Builder setRenewalPrice(Money renewalPrice) {
getInstance().renewalPrice = renewalPrice;
return this;
}
public Builder setRegistrationBehavior(RegistrationBehavior registrationBehavior) {
getInstance().registrationBehavior = registrationBehavior;
return this;

View File

@@ -30,6 +30,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.beust.jcommander.internal.Nullable;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
@@ -62,6 +63,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.inject.Inject;
import javax.inject.Named;
import org.joda.money.Money;
import org.joda.time.DateTime;
/** Command to generate and persist {@link AllocationToken}s. */
@@ -158,10 +160,16 @@ class GenerateAllocationTokensCommand implements Command {
"The type of renewal price behavior, either DEFAULT (default), NONPREMIUM, or SPECIFIED."
+ " This indicates how a domain should be charged for renewal. By default, a domain"
+ " will be renewed at the renewal price from the pricing engine. If the renewal"
+ " price behavior is set to SPECIFIED, it means that the renewal cost will be the"
+ " same as the domain's calculated create price.")
+ " price behavior is set to SPECIFIED, it means that the renewal cost will be equal"
+ " to the provided renewal price.")
private RenewalPriceBehavior renewalPriceBehavior = DEFAULT;
@Parameter(
names = {"--renewal_price"},
description = "The renewal price amount iff the renewal price behavior is SPECIFIED.")
@Nullable
private Money renewalPrice;
@Parameter(
names = {"--registration_behavior"},
description =
@@ -228,6 +236,7 @@ class GenerateAllocationTokensCommand implements Command {
Optional.ofNullable(discountYears).ifPresent(token::setDiscountYears);
Optional.ofNullable(tokenStatusTransitions)
.ifPresent(token::setTokenStatusTransitions);
Optional.ofNullable(renewalPrice).ifPresent(token::setRenewalPrice);
Optional.ofNullable(domainNames)
.ifPresent(d -> token.setDomainName(d.removeFirst()));
return token.build();
@@ -295,6 +304,10 @@ class GenerateAllocationTokensCommand implements Command {
+ " map");
}
checkArgument(
renewalPriceBehavior.equals(RenewalPriceBehavior.SPECIFIED) == (renewalPrice != null),
"renewal_price must be specified iff renewal_price_behavior is SPECIFIED");
if (tokenStrings != null) {
verifyTokenStringsDoNotExist();
}

View File

@@ -40,6 +40,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import org.joda.money.Money;
import org.joda.time.DateTime;
/** Command to update existing {@link AllocationToken}s. */
@@ -110,11 +111,17 @@ final class UpdateAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
"The type of renewal price behavior, either DEFAULT (default), NONPREMIUM, or SPECIFIED."
+ " This indicates how a domain should be charged for renewal. By default, a domain"
+ " will be renewed at the renewal price from the pricing engine. If the renewal"
+ " price behavior is set to SPECIFIED, it means that the renewal cost will be the"
+ " same as the domain's calculated create price.")
+ " price behavior is set to SPECIFIED, it means that the renewal cost will be equal"
+ " to the provided renewal price.")
@Nullable
private RenewalPriceBehavior renewalPriceBehavior;
@Parameter(
names = {"--renewal_price"},
description = "The renewal price amount iff the renewal price behavior is SPECIFIED.")
@Nullable
private Money renewalPrice;
@Parameter(
names = {"--registration_behavior"},
description =
@@ -189,17 +196,22 @@ final class UpdateAllocationTokensCommand extends UpdateOrDeleteAllocationTokens
.ifPresent(tlds -> builder.setAllowedTlds(ImmutableSet.copyOf(tlds)));
Optional.ofNullable(allowedEppActions)
.ifPresent(
eppActions -> {
builder.setAllowedEppActions(
eppActions.stream()
.map(CommandName::parseKnownCommand)
.collect(toImmutableSet()));
});
eppActions ->
builder.setAllowedEppActions(
eppActions.stream()
.map(CommandName::parseKnownCommand)
.collect(toImmutableSet())));
Optional.ofNullable(discountFraction).ifPresent(builder::setDiscountFraction);
Optional.ofNullable(discountPremiums).ifPresent(builder::setDiscountPremiums);
Optional.ofNullable(discountYears).ifPresent(builder::setDiscountYears);
Optional.ofNullable(tokenStatusTransitions).ifPresent(builder::setTokenStatusTransitions);
if (renewalPriceBehavior != null
&& renewalPriceBehavior != original.getRenewalPriceBehavior()) {
builder.setRenewalPrice(null);
}
Optional.ofNullable(renewalPriceBehavior).ifPresent(builder::setRenewalPriceBehavior);
Optional.ofNullable(renewalPrice).ifPresent(builder::setRenewalPrice);
Optional.ofNullable(registrationBehavior).ifPresent(builder::setRegistrationBehavior);
return builder.build();
}

View File

@@ -20,6 +20,7 @@ import static google.registry.testing.DatabaseHelper.persistActiveContact;
import static google.registry.testing.DatabaseHelper.persistEppResource;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.testing.LogsSubject.assertAboutLogs;
import static org.joda.money.CurrencyUnit.USD;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -111,8 +112,9 @@ public class CheckBulkComplianceActionTest {
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
bulkPricingPackage =
new BulkPricingPackage.Builder()
@@ -206,8 +208,9 @@ public class CheckBulkComplianceActionTest {
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
BulkPricingPackage bulkPricingPackage2 =
new BulkPricingPackage.Builder()
@@ -263,8 +266,9 @@ public class CheckBulkComplianceActionTest {
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
BulkPricingPackage packagePromotion2 =
new BulkPricingPackage.Builder()
@@ -338,8 +342,9 @@ public class CheckBulkComplianceActionTest {
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
BulkPricingPackage bulkPricingPackage2 =
new BulkPricingPackage.Builder()
@@ -404,8 +409,9 @@ public class CheckBulkComplianceActionTest {
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
BulkPricingPackage bulkPricingPackage2 =
new BulkPricingPackage.Builder()

View File

@@ -1371,6 +1371,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
.setTokenType(SINGLE_USE)
.setDomainName("resdom.tld")
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.build());
// Despite the domain being FULLY_BLOCKED, the non-superuser create succeeds the domain is also
// RESERVED_FOR_SPECIFIC_USE and the correct allocation token is passed.
@@ -3413,6 +3414,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
.setToken("abc123")
.setTokenType(SINGLE_USE)
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.build());
assertThat(
DomainCreateFlow.getRenewalPriceInfo(
@@ -3439,6 +3441,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
.setToken("abc123")
.setTokenType(SINGLE_USE)
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.build())),
new FeesAndCredits.Builder()
.setCurrency(USD)
@@ -3891,10 +3894,12 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.build());
persistContactsAndHosts();
setEppInput(
@@ -3919,10 +3924,12 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.build());
persistContactsAndHosts();
setEppInput(

View File

@@ -1118,8 +1118,9 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Domain> {
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
domain = domain.asBuilder().setCurrentBulkToken(token.createVKey()).build();
persistResource(domain);
@@ -1139,8 +1140,9 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Domain> {
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
domain = domain.asBuilder().setCurrentBulkToken(token.createVKey()).build();
persistResource(domain);
@@ -1172,8 +1174,9 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Domain> {
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
domain = domain.asBuilder().setCurrentBulkToken(token.createVKey()).build();
persistResource(domain);

View File

@@ -1257,9 +1257,11 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.build());
persistDomain();
@@ -1290,9 +1292,11 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.build());
persistDomain();
@@ -1327,9 +1331,11 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.build());
persistDomain(SPECIFIED, Money.of(USD, 2));
@@ -1357,9 +1363,11 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.build());
persistDomain(SPECIFIED, Money.of(USD, 2));

View File

@@ -388,7 +388,9 @@ class DomainTransferApproveFlowTest
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.build());
@@ -417,7 +419,9 @@ class DomainTransferApproveFlowTest
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());

View File

@@ -1339,7 +1339,9 @@ class DomainTransferRequestFlowTest
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -1398,7 +1400,9 @@ class DomainTransferRequestFlowTest
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -1456,7 +1460,9 @@ class DomainTransferRequestFlowTest
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());

View File

@@ -55,6 +55,8 @@ import google.registry.testing.FakeClock;
import google.registry.util.SerializeUtils;
import java.util.Arrays;
import java.util.Optional;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -134,10 +136,12 @@ public class DomainSqlTest {
new AllocationToken.Builder()
.setToken("abc123Unlimited")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("dev", "app"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setTokenStatusTransitions(
ImmutableSortedMap.<DateTime, TokenStatus>naturalOrder()

View File

@@ -842,7 +842,9 @@ public class DomainTest {
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -904,7 +906,9 @@ public class DomainTest {
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -1074,7 +1078,9 @@ public class DomainTest {
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build();
@@ -1092,7 +1098,9 @@ public class DomainTest {
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());

View File

@@ -43,6 +43,8 @@ import google.registry.model.domain.token.AllocationToken.TokenStatus;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.reporting.HistoryEntry.HistoryEntryId;
import google.registry.util.SerializeUtils;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -158,15 +160,16 @@ public class AllocationTokenTest extends EntityTestCase {
@Test
void testSetRenewalBehavior_assertsRenewalBehaviorIsNotDefault() {
assertThat(
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(SINGLE_USE)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.build())
.getRenewalPriceBehavior())
.isEqualTo(RenewalPriceBehavior.SPECIFIED);
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(SINGLE_USE)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 5))
.build());
assertThat(token.getRenewalPriceBehavior()).isEqualTo(RenewalPriceBehavior.SPECIFIED);
assertThat(token.getRenewalPrice()).hasValue(Money.of(CurrencyUnit.USD, 5));
}
@Test
@@ -181,7 +184,11 @@ public class AllocationTokenTest extends EntityTestCase {
AllocationToken loadedToken = loadByEntity(token);
assertThat(token).isEqualTo(loadedToken);
persistResource(
loadedToken.asBuilder().setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED).build());
loadedToken
.asBuilder()
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 5))
.build());
assertThat(loadByEntity(token).getRenewalPriceBehavior())
.isEqualTo(RenewalPriceBehavior.SPECIFIED);
}
@@ -218,17 +225,50 @@ public class AllocationTokenTest extends EntityTestCase {
}
@Test
void testFail_bulkTokenNotSpecifiedRenewalBehavior() {
void testFail_bulkTokenInvalidRenewalBehavior() {
assertThat(
assertThrows(
IllegalArgumentException.class,
() ->
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.BULK_PRICING)
.setDiscountFraction(1.0)
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setRenewalPriceBehavior(RenewalPriceBehavior.DEFAULT)
.build()))
.hasMessageThat()
.isEqualTo("BULK_PRICING tokens must have renewalPriceBehavior set to SPECIFIED");
assertThat(
assertThrows(
IllegalArgumentException.class,
() ->
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.BULK_PRICING)
.setDiscountFraction(1.0)
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 5))
.build()))
.hasMessageThat()
.isEqualTo("BULK_PRICING tokens must have a renewal price of 0");
}
@Test
void testFailure_bulkTokenDiscountFraction() {
AllocationToken.Builder builder =
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.BULK_PRICING)
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setRenewalPriceBehavior(RenewalPriceBehavior.DEFAULT);
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 0));
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown)
.hasMessageThat()
.isEqualTo("Bulk tokens must have renewalPriceBehavior set to SPECIFIED");
.isEqualTo("BULK_PRICING tokens must have a discountFraction of 1.0");
}
@Test
@@ -237,12 +277,14 @@ public class AllocationTokenTest extends EntityTestCase {
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.BULK_PRICING)
.setDiscountFraction(1.0)
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE, CommandName.RESTORE))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED);
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 0));
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown)
.hasMessageThat()
.isEqualTo("Bulk tokens may only be valid for CREATE actions");
.isEqualTo("BULK_PRICING tokens may only be valid for CREATE actions");
}
@Test
@@ -263,11 +305,13 @@ public class AllocationTokenTest extends EntityTestCase {
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED);
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 0));
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown)
.hasMessageThat()
.isEqualTo("Bulk tokens may only be valid for CREATE actions");
.isEqualTo("BULK_PRICING tokens may only be valid for CREATE actions");
}
@Test
@@ -276,11 +320,15 @@ public class AllocationTokenTest extends EntityTestCase {
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.BULK_PRICING)
.setDiscountFraction(1.0)
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 0))
.setDiscountPremiums(true);
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown).hasMessageThat().isEqualTo("Bulk tokens cannot discount premium names");
assertThat(thrown)
.hasMessageThat()
.isEqualTo("BULK_PRICING tokens cannot discount premium names");
}
@Test
@@ -338,8 +386,10 @@ public class AllocationTokenTest extends EntityTestCase {
new AllocationToken.Builder()
.setToken("foobar")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 0))
.setAllowedRegistrarIds(ImmutableSet.of("foo", "bar"));
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown)
@@ -536,6 +586,32 @@ public class AllocationTokenTest extends EntityTestCase {
.isEqualTo("Discount years can only be specified along with a discount fraction");
}
@Test
void testBuild_specifiedTokenInvalidBehavior() {
assertThat(
assertThrows(
IllegalArgumentException.class,
() ->
new AllocationToken.Builder()
.setToken("abc")
.setTokenType(SINGLE_USE)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.build()))
.hasMessageThat()
.isEqualTo("renewalPrice must be specified iff renewalPriceBehavior is SPECIFIED");
assertThat(
assertThrows(
IllegalArgumentException.class,
() ->
new AllocationToken.Builder()
.setToken("abc")
.setTokenType(SINGLE_USE)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 10))
.build()))
.hasMessageThat()
.isEqualTo("renewalPrice must be specified iff renewalPriceBehavior is SPECIFIED");
}
@Test
void testBuild_registrationBehaviors() {
createTld("tld");

View File

@@ -55,8 +55,9 @@ public class BulkPricingPackageTest extends EntityTestCase {
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
BulkPricingPackage bulkPricingPackage =
@@ -84,7 +85,7 @@ public class BulkPricingPackageTest extends EntityTestCase {
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
IllegalArgumentException thrown =

View File

@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static org.joda.money.CurrencyUnit.USD;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableSet;
@@ -46,8 +47,9 @@ public class CreateBulkPricingPackageCommandTest
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
runCommandForced(
"--max_domains=100",
@@ -78,7 +80,8 @@ public class CreateBulkPricingPackageCommandTest
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.setRenewalPrice(Money.of(USD, 0))
.setDiscountFraction(1.0)
.build());
IllegalArgumentException thrown =
assertThrows(
@@ -122,8 +125,9 @@ public class CreateBulkPricingPackageCommandTest
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
runCommandForced(
"--max_domains=100",
@@ -158,8 +162,9 @@ public class CreateBulkPricingPackageCommandTest
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
runCommandForced("--price=USD 1000.00", "--next_billing_date=2012-03-17T00:00:00Z", "abc123");
Optional<BulkPricingPackage> bulkPricingPackageOptional =
@@ -184,8 +189,9 @@ public class CreateBulkPricingPackageCommandTest
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
runCommandForced("--max_domains=100", "--max_creates=500", "--price=USD 1000.00", "abc123");
@@ -210,8 +216,9 @@ public class CreateBulkPricingPackageCommandTest
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
IllegalArgumentException thrown =
assertThrows(

View File

@@ -45,6 +45,8 @@ import google.registry.util.StringGenerator.Alphabets;
import java.io.File;
import java.util.Collection;
import javax.annotation.Nullable;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -194,19 +196,47 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
@Test
void testSuccess_renewalPriceBehaviorIsSpecified() throws Exception {
runCommand("--tokens", "foobar,foobaz", "--renewal_price_behavior", "SPECIFIED");
runCommand(
"--tokens",
"foobar,foobaz",
"--renewal_price_behavior",
"SPECIFIED",
"--renewal_price",
"USD 10");
assertAllocationTokens(
createToken("foobar", null, null).asBuilder().setRenewalPriceBehavior(SPECIFIED).build(),
createToken("foobaz", null, null).asBuilder().setRenewalPriceBehavior(SPECIFIED).build());
createToken("foobar", null, null)
.asBuilder()
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 10))
.build(),
createToken("foobaz", null, null)
.asBuilder()
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 10))
.build());
assertInStdout("foobar", "foobaz");
}
@Test
void testSuccess_renewalPriceBehaviorIsSpecifiedButMixedCase() throws Exception {
runCommand("--tokens", "foobar,foobaz", "--renewal_price_behavior", "speCIFied");
runCommand(
"--tokens",
"foobar,foobaz",
"--renewal_price_behavior",
"speCIFied",
"--renewal_price",
"USD 10");
assertAllocationTokens(
createToken("foobar", null, null).asBuilder().setRenewalPriceBehavior(SPECIFIED).build(),
createToken("foobaz", null, null).asBuilder().setRenewalPriceBehavior(SPECIFIED).build());
createToken("foobar", null, null)
.asBuilder()
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 10))
.build(),
createToken("foobaz", null, null)
.asBuilder()
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 10))
.build());
assertInStdout("foobar", "foobaz");
}
@@ -236,6 +266,16 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
+ " NONPREMIUM, SPECIFIED]");
}
@Test
void testFailure_specifiedPrice_withoutPrice() throws Exception {
assertThat(
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--tokens", "foobar", "--renewal_price_behavior", "SPECIFIED")))
.hasMessageThat()
.isEqualTo("renewal_price must be specified iff renewal_price_behavior is SPECIFIED");
}
@Test
void testSuccess_defaultRegistrationBehavior() throws Exception {
runCommand("--tokens", "foobar,blah");

View File

@@ -17,6 +17,7 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.money.CurrencyUnit.USD;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
@@ -52,8 +53,9 @@ public class GetBulkPricingPackageCommandTest
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
BulkPricingPackage bulkPricingPackage =
new BulkPricingPackage.Builder()
@@ -79,8 +81,9 @@ public class GetBulkPricingPackageCommandTest
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
tm().transact(
() ->
@@ -102,8 +105,9 @@ public class GetBulkPricingPackageCommandTest
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
tm().transact(
() ->

View File

@@ -40,6 +40,8 @@ import google.registry.model.domain.fee.FeeQueryCommandExtensionItem.CommandName
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.RegistrationBehavior;
import google.registry.model.domain.token.AllocationToken.TokenStatus;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
@@ -159,16 +161,22 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
@Test
void testUpdateRenewalPriceBehavior_setToSpecified() throws Exception {
AllocationToken token = persistResource(builderWithPromo().setDiscountFraction(0.5).build());
runCommandForced("--prefix", "token", "--renewal_price_behavior", "SPECIFIED");
assertThat(reloadResource(token).getRenewalPriceBehavior()).isEqualTo(SPECIFIED);
AllocationToken token = persistResource(builderWithPromo().build());
runCommandForced(
"--prefix", "token", "--renewal_price_behavior", "SPECIFIED", "--renewal_price", "USD 1");
token = reloadResource(token);
assertThat(token.getRenewalPriceBehavior()).isEqualTo(SPECIFIED);
assertThat(token.getRenewalPrice()).hasValue(Money.of(CurrencyUnit.USD, 1));
}
@Test
void testUpdateRenewalPriceBehavior_setToDefault() throws Exception {
AllocationToken token =
persistResource(
builderWithPromo().setRenewalPriceBehavior(SPECIFIED).setDiscountFraction(0.5).build());
builderWithPromo()
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 1))
.build());
runCommandForced("--prefix", "token", "--renewal_price_behavior", "default");
assertThat(reloadResource(token).getRenewalPriceBehavior()).isEqualTo(DEFAULT);
}
@@ -177,7 +185,10 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
void testUpdateRenewalPriceBehavior_setToNonPremium() throws Exception {
AllocationToken token =
persistResource(
builderWithPromo().setRenewalPriceBehavior(SPECIFIED).setDiscountFraction(0.5).build());
builderWithPromo()
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 1))
.build());
runCommandForced("--prefix", "token", "--renewal_price_behavior", "NONpremium");
assertThat(reloadResource(token).getRenewalPriceBehavior()).isEqualTo(NONPREMIUM);
}
@@ -193,11 +204,26 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
void testUpdateRenewalPriceBehavior_setFromSpecifiedToSpecified() throws Exception {
AllocationToken token =
persistResource(
builderWithPromo().setRenewalPriceBehavior(SPECIFIED).setDiscountFraction(0.5).build());
builderWithPromo()
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 1))
.build());
runCommandForced("--prefix", "token", "--renewal_price_behavior", "SPecified");
assertThat(reloadResource(token).getRenewalPriceBehavior()).isEqualTo(SPECIFIED);
}
@Test
void testFailure_nonSpecifiedToSpecified_withoutPrice() throws Exception {
persistResource(builderWithPromo().build());
assertThat(
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced("--prefix", "token", "--renewal_price_behavior", "SPECIFIED")))
.hasMessageThat()
.isEqualTo("renewalPrice must be specified iff renewalPriceBehavior is SPECIFIED");
}
@Test
void testUpdateRenewalPriceBehavior_setFromNonPremiumToDefault() throws Exception {
AllocationToken token =
@@ -214,7 +240,10 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
void testUpdateRenewalPriceBehavior_setToMixedCaseDefault() throws Exception {
AllocationToken token =
persistResource(
builderWithPromo().setRenewalPriceBehavior(SPECIFIED).setDiscountFraction(0.5).build());
builderWithPromo()
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 1))
.build());
runCommandForced("--prefix", "token", "--renewal_price_behavior", "deFauLt");
assertThat(reloadResource(token).getRenewalPriceBehavior()).isEqualTo(DEFAULT);
}
@@ -350,7 +379,9 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
new AllocationToken.Builder()
.setToken("token")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setTokenStatusTransitions(
@@ -377,7 +408,9 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
new AllocationToken.Builder()
.setToken("token")
.setTokenType(BULK_PRICING)
.setDiscountFraction(1.0)
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(CurrencyUnit.USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setTokenStatusTransitions(

View File

@@ -17,6 +17,7 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.money.CurrencyUnit.USD;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableSet;
@@ -47,8 +48,9 @@ public class UpdateBulkPricingPackageCommandTest
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
BulkPricingPackage bulkPricingPackage =
new BulkPricingPackage.Builder()
@@ -94,8 +96,9 @@ public class UpdateBulkPricingPackageCommandTest
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setAllowedEppActions(ImmutableSet.of(CommandName.CREATE))
.setDiscountFraction(1)
.setDiscountFraction(1.0)
.build());
IllegalArgumentException thrown =
assertThrows(

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -26,6 +26,8 @@
redemption_domain_repo_id text,
redemption_domain_history_id int8,
registration_behavior text not null,
renewal_price_amount numeric(19, 2),
renewal_price_currency text,
renewal_price_behavior text not null,
token_status_transitions hstore,
token_type text,