1
0
mirror of https://github.com/google/nomulus synced 2026-02-09 06:20:29 +00:00

Change PackagePromotion to BulkPricingPackage (#2096)

* Change PackagePromotion to BulkPricingPackage

* More name changes

* Fix some test names

* Change token type "BULK" to "BULK_PRICING"

* Fix missed token_type reference

* Add todo to remove package type
This commit is contained in:
sarahcaseybot
2023-08-22 16:39:24 -04:00
committed by GitHub
parent f59c387b9c
commit 1dcbc9e0cb
43 changed files with 879 additions and 836 deletions

View File

@@ -32,7 +32,7 @@ import google.registry.model.billing.BillingBase.RenewalPriceBehavior;
import google.registry.model.contact.Contact;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import google.registry.persistence.transaction.JpaTestExtensions;
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
import google.registry.testing.DatabaseHelper;
@@ -53,8 +53,8 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.ArgumentCaptor;
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;
/** Unit tests for {@link CheckPackagesComplianceAction}. */
public class CheckPackagesComplianceActionTest {
/** Unit tests for {@link CheckBulkComplianceAction}. */
public class CheckBulkComplianceActionTest {
// This is the default creation time for test data.
private final FakeClock clock = new FakeClock(DateTime.parse("2012-03-25TZ"));
private static final String CREATE_LIMIT_EMAIL_SUBJECT = "create limit subject";
@@ -72,14 +72,14 @@ public class CheckPackagesComplianceActionTest {
final JpaIntegrationTestExtension jpa =
new JpaTestExtensions.Builder().withClock(clock).buildIntegrationTestExtension();
private CheckPackagesComplianceAction action;
private CheckBulkComplianceAction action;
private AllocationToken token;
private final TestLogHandler logHandler = new TestLogHandler();
private final Logger loggerToIntercept =
Logger.getLogger(CheckPackagesComplianceAction.class.getCanonicalName());
Logger.getLogger(CheckBulkComplianceAction.class.getCanonicalName());
private final SendEmailService emailService = mock(SendEmailService.class);
private Contact contact;
private PackagePromotion packagePromotion;
private BulkPricingPackage bulkPricingPackage;
private SendEmailUtils sendEmailUtils;
private ArgumentCaptor<EmailMessage> emailCaptor = ArgumentCaptor.forClass(EmailMessage.class);
@@ -94,7 +94,7 @@ public class CheckPackagesComplianceActionTest {
emailService);
createTld("tld");
action =
new CheckPackagesComplianceAction(
new CheckBulkComplianceAction(
sendEmailUtils,
clock,
CREATE_LIMIT_EMAIL_SUBJECT,
@@ -108,19 +108,19 @@ public class CheckPackagesComplianceActionTest {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
packagePromotion =
new PackagePromotion.Builder()
bulkPricingPackage =
new BulkPricingPackage.Builder()
.setToken(token)
.setMaxDomains(3)
.setMaxCreates(1)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.setLastNotificationSent(DateTime.parse("2010-11-12T05:00:00Z"))
.build();
@@ -134,46 +134,48 @@ public class CheckPackagesComplianceActionTest {
}
@Test
void testSuccess_noPackageOverCreateLimit() {
tm().transact(() -> tm().put(packagePromotion));
void testSuccess_noBulkPackageOverCreateLimit() {
tm().transact(() -> tm().put(bulkPricingPackage));
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
verifyNoInteractions(emailService);
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found no packages over their create limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found no bulk pricing packages over their create limit.");
}
@Test
void testSuccess_onePackageOverCreateLimit() throws Exception {
tm().transact(() -> tm().put(packagePromotion));
void testSuccess_oneBulkPackageOverCreateLimit() throws Exception {
tm().transact(() -> tm().put(bulkPricingPackage));
// Create limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 1 packages over their create limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 1 bulk pricing packages over their create limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceeded their max domain creation limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceeded their max domain creation"
+ " limit by 1 name(s).");
verify(emailService).sendEmail(emailCaptor.capture());
EmailMessage emailMessage = emailCaptor.getValue();
assertThat(emailMessage.subject()).isEqualTo(CREATE_LIMIT_EMAIL_SUBJECT);
@@ -182,92 +184,93 @@ public class CheckPackagesComplianceActionTest {
}
@Test
void testSuccess_multiplePackagesOverCreateLimit() {
tm().transact(() -> tm().put(packagePromotion));
void testSuccess_multipleBulkPricingPackagesOverCreateLimit() {
tm().transact(() -> tm().put(bulkPricingPackage));
// Create limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
AllocationToken token2 =
persistResource(
new AllocationToken.Builder()
.setToken("token")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion2 =
new PackagePromotion.Builder()
BulkPricingPackage bulkPricingPackage2 =
new BulkPricingPackage.Builder()
.setToken(token2)
.setMaxDomains(8)
.setMaxCreates(1)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion2));
tm().transact(() -> tm().put(bulkPricingPackage2));
persistEppResource(
DatabaseHelper.newDomain("foo2.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz2.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 2 packages over their create limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 2 bulk pricing packages over their create limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceeded their max domain creation limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceeded their max domain creation"
+ " limit by 1 name(s).");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token token has exceeded their max domain creation limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token token has exceeded their max domain creation"
+ " limit by 1 name(s).");
verify(emailService, times(2)).sendEmail(any(EmailMessage.class));
}
@Test
void testSuccess_onlyChecksCurrentBillingYear() {
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
AllocationToken token2 =
persistResource(
new AllocationToken.Builder()
.setToken("token")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion2 =
new PackagePromotion.Builder()
BulkPricingPackage packagePromotion2 =
new BulkPricingPackage.Builder()
.setToken(token2)
.setMaxDomains(8)
.setMaxCreates(1)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2015-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion2));
@@ -276,289 +279,300 @@ public class CheckPackagesComplianceActionTest {
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found no packages over their create limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found no bulk pricing packages over their create limit.");
verifyNoInteractions(emailService);
}
@Test
void testSuccess_noPackageOverActiveDomainsLimit() {
tm().transact(() -> tm().put(packagePromotion));
void testSuccess_noBulkPricingPackageOverActiveDomainsLimit() {
tm().transact(() -> tm().put(bulkPricingPackage));
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
verifyNoInteractions(emailService);
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found no packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found no bulk pricing packages over their active domains limit.");
}
@Test
void testSuccess_onePackageOverActiveDomainsLimit() {
packagePromotion = packagePromotion.asBuilder().setMaxCreates(4).setMaxDomains(1).build();
tm().transact(() -> tm().put(packagePromotion));
void testSuccess_oneBulkPricingPackageOverActiveDomainsLimit() {
bulkPricingPackage = bulkPricingPackage.asBuilder().setMaxCreates(4).setMaxDomains(1).build();
tm().transact(() -> tm().put(bulkPricingPackage));
// Domains limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
AllocationToken token2 =
persistResource(
new AllocationToken.Builder()
.setToken("token")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion2 =
new PackagePromotion.Builder()
BulkPricingPackage bulkPricingPackage2 =
new BulkPricingPackage.Builder()
.setToken(token2)
.setMaxDomains(8)
.setMaxCreates(4)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion2));
tm().transact(() -> tm().put(bulkPricingPackage2));
persistEppResource(
DatabaseHelper.newDomain("foo2.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 1 packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 1 bulk pricing packages over their active domains limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceed their max active domains limit"
+ " by 1 name(s).");
verify(emailService).sendEmail(emailCaptor.capture());
EmailMessage emailMessage = emailCaptor.getValue();
assertThat(emailMessage.subject()).isEqualTo(DOMAIN_LIMIT_WARNING_EMAIL_SUBJECT);
assertThat(emailMessage.body())
.isEqualTo(
String.format(DOMAIN_LIMIT_WARNING_EMAIL_BODY, 1, "abc123", "The Registrar", 1, 2));
PackagePromotion packageAfterCheck =
tm().transact(() -> PackagePromotion.loadByTokenString(token.getToken()).get());
BulkPricingPackage packageAfterCheck =
tm().transact(() -> BulkPricingPackage.loadByTokenString(token.getToken()).get());
assertThat(packageAfterCheck.getLastNotificationSent().get()).isEqualTo(clock.nowUtc());
}
@Test
void testSuccess_multiplePackagesOverActiveDomainsLimit() {
void testSuccess_multipleBulkPricingPackagesOverActiveDomainsLimit() {
tm().transact(
() -> tm().put(packagePromotion.asBuilder().setMaxDomains(1).setMaxCreates(4).build()));
() ->
tm().put(bulkPricingPackage.asBuilder().setMaxDomains(1).setMaxCreates(4).build()));
// Domains limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
AllocationToken token2 =
persistResource(
new AllocationToken.Builder()
.setToken("token")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion2 =
new PackagePromotion.Builder()
BulkPricingPackage bulkPricingPackage2 =
new BulkPricingPackage.Builder()
.setToken(token2)
.setMaxDomains(1)
.setMaxCreates(5)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion2));
tm().transact(() -> tm().put(bulkPricingPackage2));
persistEppResource(
DatabaseHelper.newDomain("foo2.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz2.tld", contact)
.asBuilder()
.setCurrentPackageToken(token2.createVKey())
.setCurrentBulkToken(token2.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 2 packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 2 bulk pricing packages over their active domains limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceed their max active domains limit"
+ " by 1 name(s).");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token token has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token token has exceed their max active domains limit"
+ " by 1 name(s).");
verify(emailService, times(2)).sendEmail(any(EmailMessage.class));
}
@Test
void testSuccess_packageOverActiveDomainsLimitAlreadySentWarningEmail_DoesNotSendAgain() {
packagePromotion =
packagePromotion
void
testSuccess_bulkPricingPackageOverActiveDomainsLimitAlreadySentWarningEmail_DoesNotSendAgain() {
bulkPricingPackage =
bulkPricingPackage
.asBuilder()
.setMaxCreates(4)
.setMaxDomains(1)
.setLastNotificationSent(clock.nowUtc().minusDays(5))
.build();
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
// Domains limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 1 packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 1 bulk pricing packages over their active domains limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceed their max active domains limit"
+ " by 1 name(s).");
verifyNoInteractions(emailService);
PackagePromotion packageAfterCheck =
tm().transact(() -> PackagePromotion.loadByTokenString(token.getToken()).get());
BulkPricingPackage packageAfterCheck =
tm().transact(() -> BulkPricingPackage.loadByTokenString(token.getToken()).get());
assertThat(packageAfterCheck.getLastNotificationSent().get())
.isEqualTo(clock.nowUtc().minusDays(5));
}
@Test
void testSuccess_packageOverActiveDomainsLimitAlreadySentWarningEmailOver40DaysAgo_SendsAgain() {
packagePromotion =
packagePromotion
void
testSuccess_bulkPricingPackageOverActiveDomainsLimitAlreadySentWarningEmailOver40DaysAgo_SendsAgain() {
bulkPricingPackage =
bulkPricingPackage
.asBuilder()
.setMaxCreates(4)
.setMaxDomains(1)
.setLastNotificationSent(clock.nowUtc().minusDays(45))
.build();
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
// Domains limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 1 packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 1 bulk pricing packages over their active domains limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceed their max active domains limit"
+ " by 1 name(s).");
verify(emailService).sendEmail(emailCaptor.capture());
EmailMessage emailMessage = emailCaptor.getValue();
assertThat(emailMessage.subject()).isEqualTo(DOMAIN_LIMIT_WARNING_EMAIL_SUBJECT);
assertThat(emailMessage.body())
.isEqualTo(
String.format(DOMAIN_LIMIT_WARNING_EMAIL_BODY, 1, "abc123", "The Registrar", 1, 2));
PackagePromotion packageAfterCheck =
tm().transact(() -> PackagePromotion.loadByTokenString(token.getToken()).get());
BulkPricingPackage packageAfterCheck =
tm().transact(() -> BulkPricingPackage.loadByTokenString(token.getToken()).get());
assertThat(packageAfterCheck.getLastNotificationSent().get()).isEqualTo(clock.nowUtc());
}
@Test
void testSuccess_packageOverActiveDomainsLimitAlreadySentWarning30DaysAgo_SendsUpgradeEmail() {
packagePromotion =
packagePromotion
void
testSuccess_bulkPricingPackageOverActiveDomainsLimitAlreadySentWarning30DaysAgo_SendsUpgradeEmail() {
bulkPricingPackage =
bulkPricingPackage
.asBuilder()
.setMaxCreates(4)
.setMaxDomains(1)
.setLastNotificationSent(clock.nowUtc().minusDays(31))
.build();
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
// Domains limit is 1, creating 2 domains to go over the limit
persistEppResource(
DatabaseHelper.newDomain("foo.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
persistEppResource(
DatabaseHelper.newDomain("buzz.tld", contact)
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
action.run();
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(Level.INFO, "Found 1 packages over their active domains limit.");
.hasLogAtLevelWithMessage(
Level.INFO, "Found 1 bulk pricing packages over their active domains limit.");
assertAboutLogs()
.that(logHandler)
.hasLogAtLevelWithMessage(
Level.INFO,
"Package with package token abc123 has exceed their max active domains limit by 1"
+ " name(s).");
"Bulk pricing package with bulk token abc123 has exceed their max active domains limit"
+ " by 1 name(s).");
verify(emailService).sendEmail(emailCaptor.capture());
EmailMessage emailMessage = emailCaptor.getValue();
assertThat(emailMessage.subject()).isEqualTo(DOMAIN_LIMIT_UPGRADE_EMAIL_SUBJECT);
assertThat(emailMessage.body())
.isEqualTo(
String.format(DOMAIN_LIMIT_UPGRADE_EMAIL_BODY, 1, "abc123", "The Registrar", 1, 2));
PackagePromotion packageAfterCheck =
tm().transact(() -> PackagePromotion.loadByTokenString(token.getToken()).get());
BulkPricingPackage packageAfterCheck =
tm().transact(() -> BulkPricingPackage.loadByTokenString(token.getToken()).get());
assertThat(packageAfterCheck.getLastNotificationSent().get()).isEqualTo(clock.nowUtc());
}
}

View File

@@ -26,8 +26,8 @@ import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.DEF
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.NONPREMIUM;
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.SPECIFIED;
import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.DEFAULT_PROMO;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.model.eppcommon.StatusValue.PENDING_DELETE;
@@ -78,10 +78,10 @@ import google.registry.flows.FlowUtils.NotLoggedInException;
import google.registry.flows.FlowUtils.UnknownCurrencyEppException;
import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.domain.DomainCreateFlow.AnchorTenantCreatePeriodException;
import google.registry.flows.domain.DomainCreateFlow.BulkDomainRegisteredForTooManyYearsException;
import google.registry.flows.domain.DomainCreateFlow.MustHaveSignedMarksInCurrentPhaseException;
import google.registry.flows.domain.DomainCreateFlow.NoGeneralRegistrationsInCurrentPhaseException;
import google.registry.flows.domain.DomainCreateFlow.NoTrademarkedRegistrationsBeforeSunriseException;
import google.registry.flows.domain.DomainCreateFlow.PackageDomainRegisteredForTooManyYearsException;
import google.registry.flows.domain.DomainCreateFlow.RenewalPriceInfo;
import google.registry.flows.domain.DomainCreateFlow.SignedMarksOnlyDuringSunriseException;
import google.registry.flows.domain.DomainFlowTmchUtils.FoundMarkExpiredException;
@@ -3673,12 +3673,12 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
}
@Test
void testSuccess_packageToken_addsTokenToDomain() throws Exception {
void testSuccess_bulkToken_addsTokenToDomain() throws Exception {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
@@ -3696,16 +3696,16 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
.put("EXDATE", "2000-04-03T22:00:00.0Z")
.build()));
Domain domain = reloadResourceByForeignKey();
assertThat(domain.getCurrentPackageToken()).isPresent();
assertThat(domain.getCurrentPackageToken()).hasValue(token.createVKey());
assertThat(domain.getCurrentBulkToken()).isPresent();
assertThat(domain.getCurrentBulkToken()).hasValue(token.createVKey());
}
@Test
void testFailure_packageToken_registrationTooLong() throws Exception {
void testFailure_bulkToken_registrationTooLong() throws Exception {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
@@ -3715,10 +3715,10 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
"domain_create_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2"));
EppException thrown =
assertThrows(PackageDomainRegisteredForTooManyYearsException.class, this::runFlow);
assertThrows(BulkDomainRegisteredForTooManyYearsException.class, this::runFlow);
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"The package token abc123 cannot be used to register names for longer than 1 year.");
"The bulk token abc123 cannot be used to register names for longer than 1 year.");
}
}

View File

@@ -1091,14 +1091,14 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Domain> {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
domain = domain.asBuilder().setCurrentPackageToken(token.createVKey()).build();
domain = domain.asBuilder().setCurrentBulkToken(token.createVKey()).build();
persistResource(domain);
setEppInput("domain_info_bulk.xml");
doSuccessfulTest("domain_info_response_bulk.xml", false);
@@ -1111,14 +1111,14 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Domain> {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
domain = domain.asBuilder().setCurrentPackageToken(token.createVKey()).build();
domain = domain.asBuilder().setCurrentBulkToken(token.createVKey()).build();
persistResource(domain);
sessionMetadata.setRegistrarId("TheRegistrar");
setEppInput("domain_info_bulk.xml");
@@ -1143,14 +1143,14 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Domain> {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("NewRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
domain = domain.asBuilder().setCurrentPackageToken(token.createVKey()).build();
domain = domain.asBuilder().setCurrentBulkToken(token.createVKey()).build();
persistResource(domain);
sessionMetadata.setRegistrarId("TheRegistrar");
setEppInput("domain_info_bulk.xml");

View File

@@ -20,8 +20,8 @@ import static google.registry.flows.domain.DomainTransferFlowTestCase.persistWit
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.DEFAULT;
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.NONPREMIUM;
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.SPECIFIED;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.DEFAULT_PROMO;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
@@ -77,8 +77,8 @@ import google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTok
import google.registry.flows.domain.token.AllocationTokenFlowUtils.AllocationTokenNotValidForTldException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.AlreadyRedeemedAllocationTokenException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.InvalidAllocationTokenException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.MissingRemoveDomainTokenOnPackageDomainException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.RemoveDomainTokenOnNonPackageDomainException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.MissingRemoveDomainTokenOnBulkPricingDomainException;
import google.registry.flows.domain.token.AllocationTokenFlowUtils.RemoveDomainTokenOnNonBulkPricingDomainException;
import google.registry.flows.exceptions.ResourceStatusProhibitsOperationException;
import google.registry.model.billing.BillingBase.Flag;
import google.registry.model.billing.BillingBase.Reason;
@@ -1249,59 +1249,53 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
}
@Test
void testFailsPackageDomainInvalidAllocationToken() throws Exception {
void testFailsBulkPricingDomainInvalidAllocationToken() throws Exception {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.build());
persistDomain();
persistResource(
reloadResourceByForeignKey()
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.build());
reloadResourceByForeignKey().asBuilder().setCurrentBulkToken(token.createVKey()).build());
setEppInput(
"domain_renew_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2", "TOKEN", "abc123"));
EppException thrown =
assertThrows(MissingRemoveDomainTokenOnPackageDomainException.class, this::runFlow);
assertThrows(MissingRemoveDomainTokenOnBulkPricingDomainException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
void testFailsToRenewPackageDomainNoRemoveDomainToken() throws Exception {
void testFailsToRenewBulkPricingDomainNoRemoveDomainToken() throws Exception {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.build());
persistDomain();
persistResource(
reloadResourceByForeignKey()
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.build());
reloadResourceByForeignKey().asBuilder().setCurrentBulkToken(token.createVKey()).build());
setEppInput("domain_renew.xml", ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "5"));
EppException thrown =
assertThrows(MissingRemoveDomainTokenOnPackageDomainException.class, this::runFlow);
assertThrows(MissingRemoveDomainTokenOnBulkPricingDomainException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
void testFailsToRenewNonPackageDomainWithRemoveDomainToken() throws Exception {
void testFailsToRenewNonBulkPricingDomainWithRemoveDomainToken() throws Exception {
persistDomain();
setEppInput(
@@ -1309,7 +1303,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2", "TOKEN", "__REMOVEDOMAIN__"));
EppException thrown =
assertThrows(RemoveDomainTokenOnNonPackageDomainException.class, this::runFlow);
assertThrows(RemoveDomainTokenOnNonBulkPricingDomainException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@@ -1319,17 +1313,14 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.build());
persistDomain(SPECIFIED, Money.of(USD, 2));
persistResource(
reloadResourceByForeignKey()
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.build());
reloadResourceByForeignKey().asBuilder().setCurrentBulkToken(token.createVKey()).build());
setEppInput(
"domain_renew_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2", "TOKEN", "__REMOVEDOMAIN__"));
@@ -1339,10 +1330,10 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
2,
ImmutableMap.of("DOMAIN", "example.tld", "EXDATE", "2002-04-03T22:00:00Z"));
// We still need to verify that package token is removed as it's not being tested as a part of
// We still need to verify that the bulk token is removed as it's not being tested as a part of
// doSuccessfulTest
Domain domain = reloadResourceByForeignKey();
Truth8.assertThat(domain.getCurrentPackageToken()).isEmpty();
Truth8.assertThat(domain.getCurrentBulkToken()).isEmpty();
}
@Test
@@ -1351,17 +1342,14 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setAllowedTlds(ImmutableSet.of("tld"))
.setRenewalPriceBehavior(SPECIFIED)
.build());
persistDomain(SPECIFIED, Money.of(USD, 2));
persistResource(
reloadResourceByForeignKey()
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.build());
reloadResourceByForeignKey().asBuilder().setCurrentBulkToken(token.createVKey()).build());
setEppInput(
"domain_renew_allocationtoken.xml",

View File

@@ -17,7 +17,7 @@ package google.registry.flows.domain;
import static com.google.common.collect.MoreCollectors.onlyElement;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.model.reporting.DomainTransactionRecord.TransactionReportField.NET_ADDS_4_YR;
@@ -382,12 +382,12 @@ class DomainTransferApproveFlowTest
}
@Test
void testDryRun_PackageDomain() throws Exception {
void testDryRun_bulkPricingDomain() throws Exception {
AllocationToken allocationToken =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -398,8 +398,7 @@ class DomainTransferApproveFlowTest
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, new BigDecimal("10.00")))
.build());
persistResource(
domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
persistResource(domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
clock.advanceOneMilli();
setEppInput("domain_transfer_approve_wildcard.xml", ImmutableMap.of("DOMAIN", "example.tld"));
dryRunFlowAssertResponse(loadFile("domain_transfer_approve_response.xml"));
@@ -411,12 +410,12 @@ class DomainTransferApproveFlowTest
}
@Test
void testSuccess_removesPackageToken() throws Exception {
void testSuccess_removesBulkToken() throws Exception {
AllocationToken allocationToken =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -427,8 +426,7 @@ class DomainTransferApproveFlowTest
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, new BigDecimal("10.00")))
.build());
persistResource(
domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
persistResource(domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
clock.advanceOneMilli();
setEppInput("domain_transfer_approve_wildcard.xml", ImmutableMap.of("DOMAIN", "example.tld"));
DateTime now = clock.nowUtc();
@@ -460,7 +458,7 @@ class DomainTransferApproveFlowTest
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setRenewalPrice(Money.of(USD, new BigDecimal("10.00")))
.build());
assertThat(domain.getCurrentPackageToken()).isEmpty();
assertThat(domain.getCurrentBulkToken()).isEmpty();
assertThat(domain.getCurrentSponsorRegistrarId()).isEqualTo("NewRegistrar");
assertThat(loadByKey(domain.getAutorenewBillingEvent()).getRenewalPriceBehavior())
.isEqualTo(RenewalPriceBehavior.DEFAULT);

View File

@@ -21,7 +21,7 @@ import static com.google.common.truth.Truth8.assertThat;
import static google.registry.batch.AsyncTaskEnqueuer.PARAM_REQUESTED_TIME;
import static google.registry.batch.AsyncTaskEnqueuer.PARAM_RESOURCE_KEY;
import static google.registry.batch.AsyncTaskEnqueuer.QUEUE_ASYNC_ACTIONS;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.model.reporting.DomainTransactionRecord.TransactionReportField.TRANSFER_SUCCESSFUL;
@@ -1329,7 +1329,7 @@ class DomainTransferRequestFlowTest
}
@Test
void testSuccess_specifiedRenewalPrice_notCarriedOverForPackageName() throws Exception {
void testSuccess_specifiedRenewalPrice_notCarriedOverForBulkPricingName() throws Exception {
setupDomain("example", "tld");
persistResource(Tld.get("tld").asBuilder().build());
domain = loadByEntity(domain);
@@ -1343,13 +1343,13 @@ class DomainTransferRequestFlowTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
domain =
persistResource(
domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
DateTime now = clock.nowUtc();
setEppInput("domain_transfer_request.xml");
@@ -1388,7 +1388,7 @@ class DomainTransferRequestFlowTest
}
@Test
void testSuccess_defaultRenewalPrice_carriedOverForPackageName() throws Exception {
void testSuccess_defaultRenewalPrice_carriedOverForBulkPricingName() throws Exception {
setupDomain("example", "tld");
persistResource(Tld.get("tld").asBuilder().build());
domain = loadByEntity(domain);
@@ -1401,13 +1401,13 @@ class DomainTransferRequestFlowTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
domain =
persistResource(
domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
DateTime now = clock.nowUtc();
setEppInput("domain_transfer_request.xml");
@@ -1445,7 +1445,7 @@ class DomainTransferRequestFlowTest
}
@Test
void testSuccess_packageName_zeroPeriod() throws Exception {
void testSuccess_bulkPricingName_zeroPeriod() throws Exception {
setupDomain("example", "tld");
persistResource(Tld.get("tld").asBuilder().build());
domain = loadByEntity(domain);
@@ -1458,13 +1458,13 @@ class DomainTransferRequestFlowTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
domain =
persistResource(
domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
doSuccessfulSuperuserExtensionTest(
"domain_transfer_request_superuser_extension.xml",

View File

@@ -17,7 +17,7 @@ package google.registry.model.domain;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.insertInDb;
@@ -131,7 +131,7 @@ public class DomainSqlTest {
allocationToken =
new AllocationToken.Builder()
.setToken("abc123Unlimited")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("dev", "app"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -152,9 +152,9 @@ public class DomainSqlTest {
}
@Test
void testDomainBasePersistenceWithCurrentPackageToken() {
void testDomainBasePersistenceWithCurrentBulkToken() {
persistResource(allocationToken);
domain = domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build();
domain = domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build();
persistDomain();
assertEqualDomainExcept(loadByKey(domain.createVKey()));
}

View File

@@ -20,7 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.billing.BillingBase.RenewalPriceBehavior.SPECIFIED;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.testing.DatabaseHelper.cloneAndSetAutoTimestamps;
import static google.registry.testing.DatabaseHelper.createTld;
@@ -812,7 +812,7 @@ public class DomainTest {
}
@Test
void testClone_removesPackageFromTransferredDomain() {
void testClone_removesBulkTokenFromTransferredDomain() {
// If the transfer implicitly succeeded, the expiration time should be extended even if it
// hadn't already expired
DateTime now = DateTime.now(UTC);
@@ -831,7 +831,7 @@ public class DomainTest {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -841,13 +841,13 @@ public class DomainTest {
.asBuilder()
.setRegistrationExpirationTime(previousExpiration)
.setTransferData(transferData)
.setCurrentPackageToken(allocationToken.createVKey())
.setCurrentBulkToken(allocationToken.createVKey())
.build());
assertThat(domain.getCurrentPackageToken()).isPresent();
assertThat(domain.getCurrentBulkToken()).isPresent();
Domain clonedDomain = domain.cloneProjectedAtTime(now);
assertThat(clonedDomain.getRegistrationExpirationTime()).isEqualTo(newExpiration);
assertThat(clonedDomain.getCurrentPackageToken()).isEmpty();
assertThat(clonedDomain.getCurrentBulkToken()).isEmpty();
}
@Test
@@ -876,7 +876,7 @@ public class DomainTest {
}
@Test
void testClone_doesNotRemovePackageForPendingTransfer() {
void testClone_doesNotRemoveBulkTokenForPendingTransfer() {
// Pending transfers shouldn't affect the expiration time
DateTime now = DateTime.now(UTC);
DateTime transferExpirationTime = now.plusDays(1);
@@ -892,7 +892,7 @@ public class DomainTest {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
@@ -902,12 +902,12 @@ public class DomainTest {
.asBuilder()
.setRegistrationExpirationTime(previousExpiration)
.setTransferData(transferData)
.setCurrentPackageToken(allocationToken.createVKey())
.setCurrentBulkToken(allocationToken.createVKey())
.build());
Domain clonedDomain = domain.cloneProjectedAtTime(now);
assertThat(clonedDomain.getRegistrationExpirationTime()).isEqualTo(previousExpiration);
assertThat(clonedDomain.getCurrentPackageToken().get()).isEqualTo(allocationToken.createVKey());
assertThat(clonedDomain.getCurrentBulkToken().get()).isEqualTo(allocationToken.createVKey());
}
@Test
@@ -1043,48 +1043,48 @@ public class DomainTest {
}
@Test
void testFail_currentPackageTokenWrongPackageType() {
void testFail_currentBulkTokenWrongTokenType() {
AllocationToken allocationToken =
persistResource(
new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build());
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
() -> domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
assertThat(thrown)
.hasMessageThat()
.isEqualTo("The currentPackageToken must have a PACKAGE TokenType");
.isEqualTo("The currentBulkToken must have a BULK_PRICING TokenType");
}
@Test
void testFailure_packageTokenDoesNotExist() {
void testFailure_bulkTokenDoesNotExist() {
AllocationToken allocationToken =
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build();
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() -> domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build());
assertThat(thrown).hasMessageThat().isEqualTo("The package token abc123 does not exist");
() -> domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build());
assertThat(thrown).hasMessageThat().isEqualTo("The bulk token abc123 does not exist");
}
@Test
void testSuccess_removeCurrentPackageToken() {
void testSuccess_removeCurrentBulkToken() {
AllocationToken allocationToken =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.build());
domain = domain.asBuilder().setCurrentPackageToken(allocationToken.createVKey()).build();
assertThat(domain.getCurrentPackageToken().get()).isEqualTo(allocationToken.createVKey());
domain = domain.asBuilder().setCurrentPackageToken(null).build();
assertThat(domain.getCurrentPackageToken()).isEmpty();
domain = domain.asBuilder().setCurrentBulkToken(allocationToken.createVKey()).build();
assertThat(domain.getCurrentBulkToken().get()).isEqualTo(allocationToken.createVKey());
domain = domain.asBuilder().setCurrentBulkToken(null).build();
assertThat(domain.getCurrentBulkToken()).isEmpty();
}
}

View File

@@ -20,7 +20,7 @@ import static google.registry.model.domain.token.AllocationToken.TokenStatus.CAN
import static google.registry.model.domain.token.AllocationToken.TokenStatus.ENDED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.VALID;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.testing.DatabaseHelper.createTld;
@@ -218,28 +218,28 @@ public class AllocationTokenTest extends EntityTestCase {
}
@Test
void testFail_packageTokenNotSpecifiedRenewalBehavior() {
void testFail_bulkTokenNotSpecifiedRenewalBehavior() {
AllocationToken.Builder builder =
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.DEFAULT);
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown)
.hasMessageThat()
.isEqualTo("Package tokens must have renewalPriceBehavior set to SPECIFIED");
.isEqualTo("Bulk tokens must have renewalPriceBehavior set to SPECIFIED");
}
@Test
void testFail_packageTokenDiscountPremium() {
void testFail_bulkTokenDiscountPremium() {
AllocationToken.Builder builder =
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountPremiums(true);
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown).hasMessageThat().isEqualTo("Package tokens cannot discount premium names");
assertThat(thrown).hasMessageThat().isEqualTo("Bulk tokens cannot discount premium names");
}
@Test
@@ -292,17 +292,17 @@ public class AllocationTokenTest extends EntityTestCase {
}
@Test
void testBuild_onlyOneClientInPackage() {
void testBuild_onlyOneClientInBulkPricingPackage() {
Buildable.Builder<AllocationToken> builder =
new AllocationToken.Builder()
.setToken("foobar")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("foo", "bar"));
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
assertThat(thrown)
.hasMessageThat()
.isEqualTo("PACKAGE tokens must have exactly one allowed client registrar");
.isEqualTo("BULK_PRICING tokens must have exactly one allowed client registrar");
}
@Test

View File

@@ -31,10 +31,10 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;
/** Unit tests for {@link PackagePromotion}. */
public class PackagePromotionTest extends EntityTestCase {
/** Unit tests for {@link BulkPricingPackage}. */
public class BulkPricingPackageTest extends EntityTestCase {
public PackagePromotionTest() {
public BulkPricingPackageTest() {
super(JpaEntityCoverageCheck.ENABLED);
}
@@ -49,7 +49,7 @@ public class PackagePromotionTest extends EntityTestCase {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -57,23 +57,23 @@ public class PackagePromotionTest extends EntityTestCase {
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion =
new PackagePromotion.Builder()
BulkPricingPackage bulkPricingPackage =
new BulkPricingPackage.Builder()
.setToken(token)
.setPackagePrice(Money.of(CurrencyUnit.USD, 10000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 10000))
.setMaxCreates(40)
.setMaxDomains(10)
.setNextBillingDate(DateTime.parse("2011-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
assertAboutImmutableObjects()
.that(tm().transact(() -> PackagePromotion.loadByTokenString("abc123")).get())
.isEqualExceptFields(packagePromotion, "packagePromotionId");
.that(tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123")).get())
.isEqualExceptFields(bulkPricingPackage, "bulkPricingId");
}
@Test
void testFail_tokenIsNotPackage() {
void testFail_tokenIsNotBulkToken() {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
@@ -90,14 +90,14 @@ public class PackagePromotionTest extends EntityTestCase {
IllegalArgumentException.class,
() ->
persistResource(
new PackagePromotion.Builder()
new BulkPricingPackage.Builder()
.setToken(token)
.setPackagePrice(Money.of(CurrencyUnit.USD, 10000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 10000))
.setMaxCreates(40)
.setMaxDomains(10)
.setNextBillingDate(DateTime.parse("2011-11-12T05:00:00Z"))
.build()));
assertThat(thrown).hasMessageThat().isEqualTo("Allocation token must be a PACKAGE type");
assertThat(thrown).hasMessageThat().isEqualTo("Allocation token must be a BULK_PRICING type");
}
}

View File

@@ -23,7 +23,7 @@ import google.registry.model.console.UserTest;
import google.registry.model.contact.ContactTest;
import google.registry.model.domain.DomainSqlTest;
import google.registry.model.domain.token.AllocationTokenTest;
import google.registry.model.domain.token.PackagePromotionTest;
import google.registry.model.domain.token.BulkPricingPackageTest;
import google.registry.model.history.ContactHistoryTest;
import google.registry.model.history.DomainHistoryTest;
import google.registry.model.history.HostHistoryTest;
@@ -82,6 +82,7 @@ import org.junit.runner.RunWith;
BeforeSuiteTest.class,
AllocationTokenTest.class,
BillingBaseTest.class,
BulkPricingPackageTest.class,
ClaimsListDaoTest.class,
ContactHistoryTest.class,
ContactTest.class,
@@ -91,7 +92,6 @@ import org.junit.runner.RunWith;
DomainHistoryTest.class,
HostHistoryTest.class,
LockTest.class,
PackagePromotionTest.class,
PollMessageTest.class,
PremiumListDaoTest.class,
RdeRevisionTest.class,

View File

@@ -24,7 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.model.billing.BillingBase.RenewalPriceBehavior;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import java.util.Optional;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
@@ -32,16 +32,16 @@ import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;
/** Unit tests for {@link google.registry.tools.CreatePackagePromotionCommand}. */
public class CreatePackagePromotionCommandTest
extends CommandTestCase<CreatePackagePromotionCommand> {
/** Unit tests for {@link CreateBulkPricingPackageCommand}. */
public class CreateBulkPricingPackageCommandTest
extends CommandTestCase<CreateBulkPricingPackageCommand> {
@Test
void testSuccess() throws Exception {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -55,20 +55,20 @@ public class CreatePackagePromotionCommandTest
"--next_billing_date=2012-03-17",
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
assertThat(packagePromotion.getMaxDomains()).isEqualTo(100);
assertThat(packagePromotion.getMaxCreates()).isEqualTo(500);
assertThat(packagePromotion.getPackagePrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(packagePromotion.getNextBillingDate())
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
BulkPricingPackage bulkPricingPackage = bulkPricingPackageOptional.get();
assertThat(bulkPricingPackage.getMaxDomains()).isEqualTo(100);
assertThat(bulkPricingPackage.getMaxCreates()).isEqualTo(500);
assertThat(bulkPricingPackage.getBulkPrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(bulkPricingPackage.getNextBillingDate())
.isEqualTo(DateTime.parse("2012-03-17T00:00:00Z"));
assertThat(packagePromotion.getLastNotificationSent()).isEmpty();
assertThat(bulkPricingPackage.getLastNotificationSent()).isEmpty();
}
@Test
void testFailure_tokenIsNotPackageType() throws Exception {
void testFailure_tokenIsNotBulkType() throws Exception {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
@@ -90,7 +90,7 @@ public class CreatePackagePromotionCommandTest
"--next_billing_date=2012-03-17T05:00:00Z",
"abc123"));
assertThat(thrown.getMessage())
.isEqualTo("The allocation token must be of the PACKAGE token type");
.isEqualTo("The allocation token must be of the BULK_PRICING token type");
}
@Test
@@ -107,16 +107,16 @@ public class CreatePackagePromotionCommandTest
"abc123"));
assertThat(thrown.getMessage())
.isEqualTo(
"An allocation token with the token String abc123 does not exist. The package token"
+ " must be created first before it can be used to create a PackagePromotion");
"An allocation token with the token String abc123 does not exist. The bulk token"
+ " must be created first before it can be used to create a BulkPricingPackage");
}
@Test
void testFailure_packagePromotionAlreadyExists() throws Exception {
void testFailure_bulkPricingPackageAlreadyExists() throws Exception {
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -129,9 +129,9 @@ public class CreatePackagePromotionCommandTest
"--price=USD 1000.00",
"--next_billing_date=2012-03-17T05:00:00Z",
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
@@ -142,7 +142,8 @@ public class CreatePackagePromotionCommandTest
"--price=USD 1000.00",
"--next_billing_date=2012-03-17T05:00:00Z",
"abc123"));
assertThat(thrown.getMessage()).isEqualTo("PackagePromotion with token abc123 already exists");
assertThat(thrown.getMessage())
.isEqualTo("BulkPricingPackage with token abc123 already exists");
}
@Test
@@ -150,7 +151,7 @@ public class CreatePackagePromotionCommandTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -158,16 +159,16 @@ public class CreatePackagePromotionCommandTest
.setDiscountFraction(1)
.build());
runCommandForced("--price=USD 1000.00", "--next_billing_date=2012-03-17", "abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
assertThat(packagePromotion.getMaxDomains()).isEqualTo(0);
assertThat(packagePromotion.getMaxCreates()).isEqualTo(0);
assertThat(packagePromotion.getPackagePrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(packagePromotion.getNextBillingDate())
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
BulkPricingPackage bulkPricingPackage = bulkPricingPackageOptional.get();
assertThat(bulkPricingPackage.getMaxDomains()).isEqualTo(0);
assertThat(bulkPricingPackage.getMaxCreates()).isEqualTo(0);
assertThat(bulkPricingPackage.getBulkPrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(bulkPricingPackage.getNextBillingDate())
.isEqualTo(DateTime.parse("2012-03-17T00:00:00Z"));
assertThat(packagePromotion.getLastNotificationSent()).isEmpty();
assertThat(bulkPricingPackage.getLastNotificationSent()).isEmpty();
}
@Test
@@ -175,7 +176,7 @@ public class CreatePackagePromotionCommandTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -184,15 +185,15 @@ public class CreatePackagePromotionCommandTest
.build());
runCommandForced("--max_domains=100", "--max_creates=500", "--price=USD 1000.00", "abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
assertThat(packagePromotion.getMaxDomains()).isEqualTo(100);
assertThat(packagePromotion.getMaxCreates()).isEqualTo(500);
assertThat(packagePromotion.getPackagePrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(packagePromotion.getNextBillingDate()).isEqualTo(END_OF_TIME);
assertThat(packagePromotion.getLastNotificationSent()).isEmpty();
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
BulkPricingPackage bulkPricingPackage = bulkPricingPackageOptional.get();
assertThat(bulkPricingPackage.getMaxDomains()).isEqualTo(100);
assertThat(bulkPricingPackage.getMaxCreates()).isEqualTo(500);
assertThat(bulkPricingPackage.getBulkPrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
assertThat(bulkPricingPackage.getNextBillingDate()).isEqualTo(END_OF_TIME);
assertThat(bulkPricingPackage.getLastNotificationSent()).isEmpty();
}
@Test
@@ -200,7 +201,7 @@ public class CreatePackagePromotionCommandTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -217,6 +218,6 @@ public class CreatePackagePromotionCommandTest
"--next_billing_date=2012-03-17T05:00:00Z",
"abc123"));
assertThat(thrown.getMessage())
.isEqualTo("PackagePrice is required when creating a new package");
.isEqualTo("BulkPrice is required when creating a new bulk pricing package");
}
}

View File

@@ -379,8 +379,8 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"Invalid value for -t parameter. Allowed values:[DEFAULT_PROMO, PACKAGE, SINGLE_USE,"
+ " UNLIMITED_USE]");
"Invalid value for -t parameter. Allowed values:[BULK_PRICING, DEFAULT_PROMO, PACKAGE,"
+ " SINGLE_USE, UNLIMITED_USE]");
}
@Test
@@ -399,7 +399,7 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
}
@Test
void testFailure_invalidPackageTokenStatusTransition() {
void testFailure_invalidBulkTokenStatusTransition() {
assertThat(
assertThrows(
IllegalArgumentException.class,
@@ -408,14 +408,14 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase<GenerateAlloca
"--number",
"999",
"--type",
"PACKAGE",
"BULK_PRICING",
String.format(
"--token_status_transitions=\"%s=NOT_STARTED,%s=VALID,%s=ENDED\"",
START_OF_TIME, fakeClock.nowUtc(), fakeClock.nowUtc().plusDays(1)))))
.hasMessageThat()
.isEqualTo(
"PACKAGE tokens should not be generated with ENDED or CANCELLED in their transition"
+ " map");
"BULK_PRICING tokens should not be generated with ENDED or CANCELLED in their"
+ " transition map");
}
@Test

View File

@@ -24,15 +24,16 @@ import com.google.common.collect.ImmutableSet;
import google.registry.model.billing.BillingBase.RenewalPriceBehavior;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
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;
/** Unit tests for {@link GetPackagePromotionCommand}. */
public class GetPackagePromotionCommandTest extends CommandTestCase<GetPackagePromotionCommand> {
/** Unit tests for {@link GetBulkPricingPackageCommand}. */
public class GetBulkPricingPackageCommandTest
extends CommandTestCase<GetBulkPricingPackageCommand> {
@BeforeEach
void beforeEach() {
@@ -45,33 +46,33 @@ public class GetPackagePromotionCommandTest extends CommandTestCase<GetPackagePr
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion =
new PackagePromotion.Builder()
BulkPricingPackage bulkPricingPackage =
new BulkPricingPackage.Builder()
.setToken(token)
.setMaxDomains(100)
.setMaxCreates(500)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.setLastNotificationSent(DateTime.parse("2010-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
runCommand("abc123");
}
@Test
void testSuccessMultiplePackages() throws Exception {
void testSuccessMultipleBulkPricingPackages() throws Exception {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -81,11 +82,11 @@ public class GetPackagePromotionCommandTest extends CommandTestCase<GetPackagePr
tm().transact(
() ->
tm().put(
new PackagePromotion.Builder()
new BulkPricingPackage.Builder()
.setToken(token)
.setMaxDomains(100)
.setMaxCreates(500)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.setLastNotificationSent(DateTime.parse("2010-11-12T05:00:00Z"))
.build()));
@@ -93,7 +94,7 @@ public class GetPackagePromotionCommandTest extends CommandTestCase<GetPackagePr
persistResource(
new AllocationToken.Builder()
.setToken("123abc")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2012-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -103,11 +104,11 @@ public class GetPackagePromotionCommandTest extends CommandTestCase<GetPackagePr
tm().transact(
() ->
tm().put(
new PackagePromotion.Builder()
new BulkPricingPackage.Builder()
.setToken(token2)
.setMaxDomains(1000)
.setMaxCreates(700)
.setPackagePrice(Money.of(CurrencyUnit.USD, 3000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 3000))
.setNextBillingDate(DateTime.parse("2014-11-12T05:00:00Z"))
.setLastNotificationSent(DateTime.parse("2013-11-12T05:00:00Z"))
.build()));
@@ -116,12 +117,12 @@ public class GetPackagePromotionCommandTest extends CommandTestCase<GetPackagePr
}
@Test
void testFailure_packageDoesNotExist() {
void testFailure_bulkPricingPackageDoesNotExist() {
IllegalArgumentException thrown =
assertThrows(IllegalArgumentException.class, () -> runCommand("fakeToken"));
assertThat(thrown)
.hasMessageThat()
.isEqualTo("PackagePromotion with package token fakeToken does not exist");
.isEqualTo("BulkPricingPackage with token fakeToken does not exist");
}
@Test

View File

@@ -22,7 +22,7 @@ import static google.registry.model.domain.token.AllocationToken.TokenStatus.CAN
import static google.registry.model.domain.token.AllocationToken.TokenStatus.ENDED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.NOT_STARTED;
import static google.registry.model.domain.token.AllocationToken.TokenStatus.VALID;
import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE;
import static google.registry.model.domain.token.AllocationToken.TokenType.BULK_PRICING;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
import static google.registry.testing.DatabaseHelper.createTld;
@@ -344,13 +344,13 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
}
@Test
void testUpdateStatusTransitions_endPackageTokenNoDomains() throws Exception {
void testUpdateStatusTransitions_endBulkTokenNoDomains() throws Exception {
DateTime now = fakeClock.nowUtc();
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("token")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setTokenStatusTransitions(
@@ -371,13 +371,13 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
}
@Test
void testUpdateStatusTransitions_endPackageTokenWithActiveDomainsFails() throws Exception {
void testUpdateStatusTransitions_endBulkTokenWithActiveDomainsFails() throws Exception {
DateTime now = fakeClock.nowUtc();
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("token")
.setTokenType(PACKAGE)
.setTokenType(BULK_PRICING)
.setRenewalPriceBehavior(SPECIFIED)
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setTokenStatusTransitions(
@@ -390,7 +390,7 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
persistResource(
persistActiveDomain("example.tld")
.asBuilder()
.setCurrentPackageToken(token.createVKey())
.setCurrentBulkToken(token.createVKey())
.build());
IllegalArgumentException thrown =
assertThrows(
@@ -406,8 +406,8 @@ class UpdateAllocationTokensCommandTest extends CommandTestCase<UpdateAllocation
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"Package token token can not end its promotion because it still has 1 domains in the"
+ " package");
"Bulk token token can not end its promotion because it still has 1 domains in the"
+ " promotion");
}
@Test

View File

@@ -23,7 +23,7 @@ import com.google.common.truth.Truth;
import google.registry.model.billing.BillingBase.RenewalPriceBehavior;
import google.registry.model.domain.token.AllocationToken;
import google.registry.model.domain.token.AllocationToken.TokenType;
import google.registry.model.domain.token.PackagePromotion;
import google.registry.model.domain.token.BulkPricingPackage;
import java.util.Optional;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
@@ -32,9 +32,9 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.shaded.com.google.common.collect.ImmutableSet;
/** Unit tests for {@link google.registry.tools.UpdatePackagePromotionCommand}. */
public class UpdatePackagePromotionCommandTest
extends CommandTestCase<UpdatePackagePromotionCommand> {
/** Unit tests for {@link UpdateBulkPricingPackageCommand}. */
public class UpdateBulkPricingPackageCommandTest
extends CommandTestCase<UpdateBulkPricingPackageCommand> {
@BeforeEach
void beforeEach() {
@@ -42,23 +42,23 @@ public class UpdatePackagePromotionCommandTest
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.setDiscountFraction(1)
.build());
PackagePromotion packagePromotion =
new PackagePromotion.Builder()
BulkPricingPackage bulkPricingPackage =
new BulkPricingPackage.Builder()
.setToken(token)
.setMaxDomains(100)
.setMaxCreates(500)
.setPackagePrice(Money.of(CurrencyUnit.USD, 1000))
.setBulkPrice(Money.of(CurrencyUnit.USD, 1000))
.setNextBillingDate(DateTime.parse("2012-11-12T05:00:00Z"))
.setLastNotificationSent(DateTime.parse("2010-11-12T05:00:00Z"))
.build();
tm().transact(() -> tm().put(packagePromotion));
tm().transact(() -> tm().put(bulkPricingPackage));
}
@Test
@@ -71,25 +71,24 @@ public class UpdatePackagePromotionCommandTest
"--clear_last_notification_sent",
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
Truth.assertThat(packagePromotion.getMaxDomains()).isEqualTo(200);
Truth.assertThat(packagePromotion.getMaxCreates()).isEqualTo(1000);
Truth.assertThat(packagePromotion.getPackagePrice())
.isEqualTo(Money.of(CurrencyUnit.USD, 2000));
Truth.assertThat(packagePromotion.getNextBillingDate())
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
BulkPricingPackage bulkPricingPackage = bulkPricingPackageOptional.get();
Truth.assertThat(bulkPricingPackage.getMaxDomains()).isEqualTo(200);
Truth.assertThat(bulkPricingPackage.getMaxCreates()).isEqualTo(1000);
Truth.assertThat(bulkPricingPackage.getBulkPrice()).isEqualTo(Money.of(CurrencyUnit.USD, 2000));
Truth.assertThat(bulkPricingPackage.getNextBillingDate())
.isEqualTo(DateTime.parse("2013-03-17T00:00:00Z"));
assertThat(packagePromotion.getLastNotificationSent()).isEmpty();
assertThat(bulkPricingPackage.getLastNotificationSent()).isEmpty();
}
@Test
void testFailure_packageDoesNotExist() throws Exception {
void testFailure_bulkPackageDoesNotExist() throws Exception {
persistResource(
new AllocationToken.Builder()
.setToken("nullPackage")
.setTokenType(TokenType.PACKAGE)
.setTokenType(TokenType.BULK_PRICING)
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
.setAllowedTlds(ImmutableSet.of("foo"))
.setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar"))
@@ -107,7 +106,7 @@ public class UpdatePackagePromotionCommandTest
"--next_billing_date=2012-03-17",
"nullPackage"));
Truth.assertThat(thrown.getMessage())
.isEqualTo("PackagePromotion with token nullPackage does not exist");
.isEqualTo("BulkPricingPackage with token nullPackage does not exist");
}
@Test
@@ -119,17 +118,16 @@ public class UpdatePackagePromotionCommandTest
"--clear_last_notification_sent",
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
Truth.assertThat(packagePromotion.getMaxDomains()).isEqualTo(100);
Truth.assertThat(packagePromotion.getMaxCreates()).isEqualTo(1000);
Truth.assertThat(packagePromotion.getPackagePrice())
.isEqualTo(Money.of(CurrencyUnit.USD, 2000));
Truth.assertThat(packagePromotion.getNextBillingDate())
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
BulkPricingPackage bulkPricingPackage = bulkPricingPackageOptional.get();
Truth.assertThat(bulkPricingPackage.getMaxDomains()).isEqualTo(100);
Truth.assertThat(bulkPricingPackage.getMaxCreates()).isEqualTo(1000);
Truth.assertThat(bulkPricingPackage.getBulkPrice()).isEqualTo(Money.of(CurrencyUnit.USD, 2000));
Truth.assertThat(bulkPricingPackage.getNextBillingDate())
.isEqualTo(DateTime.parse("2013-03-17T00:00:00Z"));
assertThat(packagePromotion.getLastNotificationSent()).isEmpty();
assertThat(bulkPricingPackage.getLastNotificationSent()).isEmpty();
}
@Test
@@ -141,17 +139,16 @@ public class UpdatePackagePromotionCommandTest
"--clear_last_notification_sent",
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
Truth.assertThat(packagePromotion.getMaxDomains()).isEqualTo(200);
Truth.assertThat(packagePromotion.getMaxCreates()).isEqualTo(1000);
Truth.assertThat(packagePromotion.getPackagePrice())
.isEqualTo(Money.of(CurrencyUnit.USD, 2000));
Truth.assertThat(packagePromotion.getNextBillingDate())
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
BulkPricingPackage bulkPricingPackage = bulkPricingPackageOptional.get();
Truth.assertThat(bulkPricingPackage.getMaxDomains()).isEqualTo(200);
Truth.assertThat(bulkPricingPackage.getMaxCreates()).isEqualTo(1000);
Truth.assertThat(bulkPricingPackage.getBulkPrice()).isEqualTo(Money.of(CurrencyUnit.USD, 2000));
Truth.assertThat(bulkPricingPackage.getNextBillingDate())
.isEqualTo(DateTime.parse("2012-11-12T05:00:00Z"));
assertThat(packagePromotion.getLastNotificationSent()).isEmpty();
assertThat(bulkPricingPackage.getLastNotificationSent()).isEmpty();
}
@Test
@@ -163,34 +160,32 @@ public class UpdatePackagePromotionCommandTest
"--clear_last_notification_sent",
"abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
Truth.assertThat(packagePromotion.getMaxDomains()).isEqualTo(200);
Truth.assertThat(packagePromotion.getMaxCreates()).isEqualTo(1000);
Truth.assertThat(packagePromotion.getPackagePrice())
.isEqualTo(Money.of(CurrencyUnit.USD, 1000));
Truth.assertThat(packagePromotion.getNextBillingDate())
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
BulkPricingPackage bulkPricingPackage = bulkPricingPackageOptional.get();
Truth.assertThat(bulkPricingPackage.getMaxDomains()).isEqualTo(200);
Truth.assertThat(bulkPricingPackage.getMaxCreates()).isEqualTo(1000);
Truth.assertThat(bulkPricingPackage.getBulkPrice()).isEqualTo(Money.of(CurrencyUnit.USD, 1000));
Truth.assertThat(bulkPricingPackage.getNextBillingDate())
.isEqualTo(DateTime.parse("2013-03-17T00:00:00Z"));
assertThat(packagePromotion.getLastNotificationSent()).isEmpty();
assertThat(bulkPricingPackage.getLastNotificationSent()).isEmpty();
}
@Test
void testSuccess_dontClearLastNotificationSent() throws Exception {
runCommandForced("--max_domains=200", "--max_creates=1000", "--price=USD 2000.00", "abc123");
Optional<PackagePromotion> packagePromotionOptional =
tm().transact(() -> PackagePromotion.loadByTokenString("abc123"));
assertThat(packagePromotionOptional).isPresent();
PackagePromotion packagePromotion = packagePromotionOptional.get();
Truth.assertThat(packagePromotion.getMaxDomains()).isEqualTo(200);
Truth.assertThat(packagePromotion.getMaxCreates()).isEqualTo(1000);
Truth.assertThat(packagePromotion.getPackagePrice())
.isEqualTo(Money.of(CurrencyUnit.USD, 2000));
Truth.assertThat(packagePromotion.getNextBillingDate())
Optional<BulkPricingPackage> bulkPricingPackageOptional =
tm().transact(() -> BulkPricingPackage.loadByTokenString("abc123"));
assertThat(bulkPricingPackageOptional).isPresent();
BulkPricingPackage bulkPricingPackage = bulkPricingPackageOptional.get();
Truth.assertThat(bulkPricingPackage.getMaxDomains()).isEqualTo(200);
Truth.assertThat(bulkPricingPackage.getMaxCreates()).isEqualTo(1000);
Truth.assertThat(bulkPricingPackage.getBulkPrice()).isEqualTo(Money.of(CurrencyUnit.USD, 2000));
Truth.assertThat(bulkPricingPackage.getNextBillingDate())
.isEqualTo(DateTime.parse("2012-11-12T05:00:00Z"));
Truth.assertThat(packagePromotion.getLastNotificationSent().get())
Truth.assertThat(bulkPricingPackage.getLastNotificationSent().get())
.isEqualTo(DateTime.parse("2010-11-12T05:00:00.000Z"));
}
}