1
0
mirror of https://github.com/google/nomulus synced 2026-06-05 14:32:51 +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

@@ -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(