Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor logic out of domain create flow tests #2688

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@
import google.registry.model.domain.Domain;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.fee.BaseFee.FeeType;
import google.registry.model.domain.fee.Fee;
import google.registry.model.domain.fee.FeeQueryCommandExtensionItem.CommandName;
import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.rgp.GracePeriodStatus;
Expand Down Expand Up @@ -287,59 +285,45 @@ private void persistContactsAndHosts() {
persistContactsAndHosts("net"); // domain_create.xml uses hosts on "net".
}

private void assertSuccessfulCreate(String domainTld, ImmutableSet<Flag> expectedBillingFlags)
throws Exception {
assertSuccessfulCreate(domainTld, expectedBillingFlags, null, 24, null);
}

private void assertSuccessfulCreate(
String domainTld, ImmutableSet<Flag> expectedBillingFlags, double createCost)
throws Exception {
assertSuccessfulCreate(domainTld, expectedBillingFlags, null, createCost, null);
}

private void assertSuccessfulCreate(
String domainTld, ImmutableSet<BillingBase.Flag> expectedBillingFlags) throws Exception {
assertSuccessfulCreate(domainTld, expectedBillingFlags, null);
String domainTld, ImmutableSet<Flag> expectedBillingFlags, AllocationToken token)
throws Exception {
assertSuccessfulCreate(domainTld, expectedBillingFlags, token, 24, null);
}

private void assertSuccessfulCreate(
String domainTld,
ImmutableSet<BillingBase.Flag> expectedBillingFlags,
@Nullable AllocationToken allocationToken)
ImmutableSet<Flag> expectedBillingFlags,
AllocationToken token,
double createCost)
throws Exception {
assertSuccessfulCreate(domainTld, expectedBillingFlags, token, createCost, null);
}

private void assertSuccessfulCreate(
String domainTld,
ImmutableSet<Flag> expectedBillingFlags,
@Nullable AllocationToken token,
double createCost,
@Nullable Integer specifiedRenewCost)
throws Exception {
Domain domain = reloadResourceByForeignKey();

boolean isAnchorTenant = expectedBillingFlags.contains(ANCHOR_TENANT);
// Set up the creation cost.
boolean isDomainPremium = isDomainPremium(getUniqueIdFromCommand(), clock.nowUtc());
BigDecimal createCost = isDomainPremium ? BigDecimal.valueOf(200) : BigDecimal.valueOf(24);
if (isAnchorTenant) {
createCost = BigDecimal.ZERO;
}
if (expectedBillingFlags.contains(SUNRISE)) {
createCost =
createCost.multiply(
BigDecimal.valueOf(1 - RegistryConfig.getSunriseDomainCreateDiscount()));
}
if (allocationToken != null) {
if (allocationToken
.getRegistrationBehavior()
.equals(RegistrationBehavior.NONPREMIUM_CREATE)) {
createCost =
createCost.subtract(
BigDecimal.valueOf(isDomainPremium ? 87 : 0)); // premium is 100, standard 13
}
if (allocationToken.getRenewalPriceBehavior().equals(NONPREMIUM)) {
createCost =
createCost.subtract(
BigDecimal.valueOf(isDomainPremium ? 89 : 0)); // premium is 100, standard 11
}
if (allocationToken.getRenewalPriceBehavior().equals(SPECIFIED)) {
createCost =
createCost
.subtract(BigDecimal.valueOf(isDomainPremium ? 100 : 11))
.add(allocationToken.getRenewalPrice().get().getAmount());
}
}
FeesAndCredits feesAndCredits =
new FeesAndCredits.Builder()
.setCurrency(USD)
.addFeeOrCredit(
Fee.create(
createCost,
FeeType.CREATE,
isDomainPremium(getUniqueIdFromCommand(), clock.nowUtc())))
.build();

Money eapFee =
Money.of(
Tld.get(domainTld).getCurrency(),
Expand All @@ -362,7 +346,7 @@ private void assertSuccessfulCreate(
RenewalPriceBehavior expectedRenewalPriceBehavior =
isAnchorTenant
? RenewalPriceBehavior.NONPREMIUM
: Optional.ofNullable(allocationToken)
: Optional.ofNullable(token)
.map(AllocationToken::getRenewalPriceBehavior)
.orElse(RenewalPriceBehavior.DEFAULT);
// There should be one bill for the create and one for the recurrence autorenew event.
Expand All @@ -371,13 +355,13 @@ private void assertSuccessfulCreate(
.setReason(Reason.CREATE)
.setTargetId(getUniqueIdFromCommand())
.setRegistrarId("TheRegistrar")
.setCost(feesAndCredits.getCreateCost())
.setCost(Money.of(USD, BigDecimal.valueOf(createCost)))
.setPeriodYears(2)
.setEventTime(clock.nowUtc())
.setBillingTime(billingTime)
.setFlags(expectedBillingFlags)
.setDomainHistory(historyEntry)
.setAllocationToken(allocationToken == null ? null : allocationToken.createVKey())
.setAllocationToken(Optional.ofNullable(token).map(t -> t.createVKey()).orElse(null))
.build();

BillingRecurrence renewBillingEvent =
Expand All @@ -391,8 +375,8 @@ private void assertSuccessfulCreate(
.setDomainHistory(historyEntry)
.setRenewalPriceBehavior(expectedRenewalPriceBehavior)
.setRenewalPrice(
Optional.ofNullable(allocationToken)
.flatMap(AllocationToken::getRenewalPrice)
Optional.ofNullable(specifiedRenewCost)
.map(r -> Money.of(USD, BigDecimal.valueOf(r)))
.orElse(null))
.build();

Expand Down Expand Up @@ -480,7 +464,7 @@ private void doSuccessfulTest(
assertMutatingFlow(true);
runFlowAssertResponse(
CommitMode.LIVE, userPrivileges, loadFile(responseXmlFile, substitutions));
assertSuccessfulCreate(domainTld, ImmutableSet.of());
assertSuccessfulCreate(domainTld, ImmutableSet.of(), 24);
assertNoLordn();
}

Expand Down Expand Up @@ -886,10 +870,14 @@ void testSuccess_premiumAndEap() throws Exception {
clock.nowUtc().plusDays(1),
Money.of(USD, 0)))
.build());
doSuccessfulTest(
"example",
"domain_create_response_premium_eap.xml",
ImmutableMap.of("DOMAIN", "rich.example"));
assertMutatingFlow(true);
runFlowAssertResponse(
CommitMode.LIVE,
UserPrivileges.NORMAL,
loadFile(
"domain_create_response_premium_eap.xml", ImmutableMap.of("DOMAIN", "rich.example")));
assertSuccessfulCreate("example", ImmutableSet.of(), 200);
assertNoLordn();
}

/**
Expand Down Expand Up @@ -1336,7 +1324,7 @@ void testSuccess_anchorTenant() throws Exception {
setEppInput("domain_create_anchor_allocationtoken.xml");
persistContactsAndHosts();
runFlowAssertResponse(loadFile("domain_create_anchor_response.xml"));
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken, 0);
assertNoLordn();
assertAllocationTokenWasRedeemed("abcDEF23456");
}
Expand All @@ -1350,7 +1338,7 @@ void testSuccess_internalRegistrationWithSpecifiedRenewalPrice() throws Exceptio
.setTokenType(SINGLE_USE)
.setDomainName("resdom.tld")
.setRenewalPriceBehavior(SPECIFIED)
.setRenewalPrice(Money.of(USD, 0))
.setRenewalPrice(Money.of(USD, 1))
.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.
Expand All @@ -1359,7 +1347,8 @@ void testSuccess_internalRegistrationWithSpecifiedRenewalPrice() throws Exceptio
persistContactsAndHosts();
runFlowAssertResponse(
loadFile("domain_create_response.xml", ImmutableMap.of("DOMAIN", "resdom.tld")));
assertSuccessfulCreate("tld", ImmutableSet.of(RESERVED), allocationToken);
// $13 for the first year plus $1 renewal for the second year =
assertSuccessfulCreate("tld", ImmutableSet.of(RESERVED), allocationToken, 14, 1);
assertNoLordn();
assertAllocationTokenWasRedeemed("abc123");
}
Expand All @@ -1379,7 +1368,7 @@ void testSuccess_anchorTenant_bypassesEapFees() throws Exception {
setEppInput("domain_create_anchor_allocationtoken.xml");
persistContactsAndHosts();
runFlowAssertResponse(loadFile("domain_create_anchor_response.xml"));
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken, 0);
assertNoLordn();
assertAllocationTokenWasRedeemed("abcDEF23456");
}
Expand All @@ -1402,7 +1391,7 @@ void testSuccess_anchorTenant_withClaims() throws Exception {
clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z"));
persistContactsAndHosts();
runFlowAssertResponse(loadFile("domain_create_response_claims.xml"));
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken, 0);
assertDomainDnsRequests("example-one.tld");
assertClaimsLordn();
assertAllocationTokenWasRedeemed("abcDEF23456");
Expand All @@ -1415,7 +1404,7 @@ void testSuccess_anchorTenant_withMetadataExtension() throws Exception {
persistContactsAndHosts();
runFlowAssertResponse(
loadFile("domain_create_response.xml", ImmutableMap.of("DOMAIN", "example.tld")));
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT));
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), 0);
assertNoLordn();
}

Expand Down Expand Up @@ -1450,7 +1439,7 @@ void testSuccess_anchorTenantInSunrise_withMetadataExtension_andSignedMark() thr
SMD_VALID_TIME.toString(),
"EXPIRATION_TIME",
SMD_VALID_TIME.plusYears(2).toString())));
assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE, ANCHOR_TENANT));
assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE, ANCHOR_TENANT), 0);
}

@Test
Expand Down Expand Up @@ -1482,7 +1471,7 @@ void testSuccess_anchorTenantInSunrise_withSignedMark() throws Exception {
SMD_VALID_TIME.toString(),
"EXPIRATION_TIME",
SMD_VALID_TIME.plusYears(2).toString())));
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT, SUNRISE), allocationToken);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT, SUNRISE), allocationToken, 0);
assertDomainDnsRequests("test-validate.tld");
assertSunriseLordn();
assertAllocationTokenWasRedeemed("abcDEF23456");
Expand All @@ -1505,7 +1494,7 @@ void testSuccess_anchorTenant_duringQuietPeriodBeforeSunrise() throws Exception
setEppInput("domain_create_anchor_allocationtoken.xml");
persistContactsAndHosts();
runFlowAssertResponse(loadFile("domain_create_anchor_response.xml"));
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken, 0);
assertNoLordn();
assertAllocationTokenWasRedeemed("abcDEF23456");
}
Expand Down Expand Up @@ -1929,7 +1918,7 @@ void testSuccess_doesNotApplyNonPremiumDefaultTokenToPremiumName() throws Except
loadFile(
"domain_create_response_premium.xml",
ImmutableMap.of("EXDATE", "2001-04-03T22:00:00.0Z", "FEE", "200.00")));
assertSuccessfulCreate("example", ImmutableSet.of());
assertSuccessfulCreate("example", ImmutableSet.of(), 200);
}

private BillingEvent runTest_defaultToken(String token) throws Exception {
Expand Down Expand Up @@ -2148,7 +2137,7 @@ void testSuccess_superuserOverridesPremiumNameBlock() throws Exception {
loadFile(
"domain_create_response_premium.xml",
ImmutableMap.of("EXDATE", "2001-04-03T22:00:00.0Z", "FEE", "200.00")));
assertSuccessfulCreate("example", ImmutableSet.of());
assertSuccessfulCreate("example", ImmutableSet.of(), 200);
}

@Test
Expand Down Expand Up @@ -2572,7 +2561,7 @@ void testSuccess_blockedByBsa_anchorTenant() throws Exception {
persistContactsAndHosts();
persistBsaLabel("anchor");
runFlowAssertResponse(loadFile("domain_create_anchor_response.xml"));
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken, 0);
assertNoLordn();
assertAllocationTokenWasRedeemed("abcDEF23456");
}
Expand Down Expand Up @@ -2738,7 +2727,7 @@ void testSuccess_startDateSunriseRegistration_withEncodedSignedMark() throws Exc
SMD_VALID_TIME.toString(),
"EXPIRATION_TIME",
SMD_VALID_TIME.plusYears(2).toString())));
assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE));
assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE), 20.40);
assertSunriseLordn();
}

Expand All @@ -2761,7 +2750,7 @@ void testSuccess_startDateSunriseRegistration_withEncodedSignedMark_noType() thr
SMD_VALID_TIME.toString(),
"EXPIRATION_TIME",
SMD_VALID_TIME.plusYears(2).toString())));
assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE));
assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE), 20.40);
assertSunriseLordn();
}

Expand Down Expand Up @@ -3245,7 +3234,7 @@ void testSuccess_anchorTenant_nonPremiumRenewal() throws Exception {
"domain_create_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2"));
runFlow();
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), token);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), token, 0);
}

@Test
Expand All @@ -3265,7 +3254,7 @@ void testSuccess_nonAnchorTenant_nonPremiumRenewal() throws Exception {
"domain_create_premium_allocationtoken.xml",
ImmutableMap.of("YEARS", "2", "FEE", "111.00"));
runFlow();
assertSuccessfulCreate("example", ImmutableSet.of(), token);
assertSuccessfulCreate("example", ImmutableSet.of(), token, 111);
}

@Test
Expand All @@ -3286,7 +3275,7 @@ void testSuccess_specifiedRenewalPriceToken_specifiedRecurrencePrice() throws Ex
"domain_create_premium_allocationtoken.xml",
ImmutableMap.of("YEARS", "2", "FEE", "101.00"));
runFlow();
assertSuccessfulCreate("example", ImmutableSet.of(), token);
assertSuccessfulCreate("example", ImmutableSet.of(), token, 101, 1);
}

@Test
Expand Down Expand Up @@ -3438,7 +3427,7 @@ void testSuccess_anchorTenant_quietPeriodBeforeSunrise_nonTrademarked_viaToken()
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2"));
persistContactsAndHosts();
runFlow();
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), token);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), token, 0);
}

@Test
Expand Down Expand Up @@ -3492,7 +3481,7 @@ void testSuccess_anchorTenant_inSunrise_nonTrademarked_viaToken() throws Excepti
"domain_create_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2"));
runFlow();
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), token);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), token, 0);
}

@Test
Expand All @@ -3510,7 +3499,7 @@ void testSuccess_anchorTenant_inSunrise_trademarked_withSignedMark_viaToken() th
.build());
persistContactsAndHosts();
runFlow();
assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE, ANCHOR_TENANT), allocationToken);
assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE, ANCHOR_TENANT), allocationToken, 0);
}

@Test
Expand Down Expand Up @@ -3572,7 +3561,7 @@ void testSuccess_anchorTenant_quietPeriodAfterSunrise_nonTrademarked_viaToken()
"domain_create_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2"));
runFlow();
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), token);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), token, 0);
}

@Test
Expand All @@ -3599,7 +3588,7 @@ void testSuccess_anchorTenant_quietPeriodAfterSunrise_trademarked_withClaims_via
setEppInput("domain_create_allocationtoken_claims.xml");
persistContactsAndHosts();
runFlow();
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken, 0);
}

@Test
Expand Down Expand Up @@ -3649,7 +3638,7 @@ void testSuccess_anchorTenant_ga_nonTrademarked_viaToken() throws Exception {
"domain_create_allocationtoken.xml",
ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2"));
runFlow();
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), token);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), token, 0);
}

@Test
Expand All @@ -3663,7 +3652,7 @@ void testSuccess_anchorTenant_ga_trademarked_withClaims_viaToken() throws Except
setEppInput("domain_create_allocationtoken_claims.xml");
persistContactsAndHosts();
runFlow();
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken);
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken, 0);
}

@Test
Expand Down