mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 16:37:13 +02:00
Store a reference to an allocation token in the OneTime billing event
We will need to be able to find all redemptions associated with a particular token and this will allow us to do that. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=245292865
This commit is contained in:
parent
d02a01ba66
commit
a0f9e3b3dd
5 changed files with 121 additions and 48 deletions
|
@ -295,6 +295,7 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
years,
|
years,
|
||||||
feesAndCredits,
|
feesAndCredits,
|
||||||
historyEntry,
|
historyEntry,
|
||||||
|
allocationToken,
|
||||||
now);
|
now);
|
||||||
// Create a new autorenew billing event and poll message starting at the expiration time.
|
// Create a new autorenew billing event and poll message starting at the expiration time.
|
||||||
BillingEvent.Recurring autorenewBillingEvent =
|
BillingEvent.Recurring autorenewBillingEvent =
|
||||||
|
@ -477,6 +478,7 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
int years,
|
int years,
|
||||||
FeesAndCredits feesAndCredits,
|
FeesAndCredits feesAndCredits,
|
||||||
HistoryEntry historyEntry,
|
HistoryEntry historyEntry,
|
||||||
|
Optional<AllocationToken> allocationToken,
|
||||||
DateTime now) {
|
DateTime now) {
|
||||||
ImmutableSet.Builder<Flag> flagsBuilder = new ImmutableSet.Builder<>();
|
ImmutableSet.Builder<Flag> flagsBuilder = new ImmutableSet.Builder<>();
|
||||||
// Sunrise and anchor tenancy are orthogonal tags and thus both can be present together.
|
// Sunrise and anchor tenancy are orthogonal tags and thus both can be present together.
|
||||||
|
@ -497,6 +499,7 @@ public class DomainCreateFlow implements TransactionalFlow {
|
||||||
.setPeriodYears(years)
|
.setPeriodYears(years)
|
||||||
.setCost(feesAndCredits.getCreateCost())
|
.setCost(feesAndCredits.getCreateCost())
|
||||||
.setEventTime(now)
|
.setEventTime(now)
|
||||||
|
.setAllocationToken(allocationToken.map(Key::create).orElse(null))
|
||||||
.setBillingTime(
|
.setBillingTime(
|
||||||
now.plus(
|
now.plus(
|
||||||
isAnchorTenant
|
isAnchorTenant
|
||||||
|
|
|
@ -40,6 +40,7 @@ import google.registry.model.annotations.ReportedOn;
|
||||||
import google.registry.model.common.TimeOfYear;
|
import google.registry.model.common.TimeOfYear;
|
||||||
import google.registry.model.domain.GracePeriod;
|
import google.registry.model.domain.GracePeriod;
|
||||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||||
|
import google.registry.model.domain.token.AllocationToken;
|
||||||
import google.registry.model.reporting.HistoryEntry;
|
import google.registry.model.reporting.HistoryEntry;
|
||||||
import google.registry.model.transfer.TransferData.TransferServerApproveEntity;
|
import google.registry.model.transfer.TransferData.TransferServerApproveEntity;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -244,6 +245,11 @@ public abstract class BillingEvent extends ImmutableObject
|
||||||
*/
|
*/
|
||||||
Key<? extends BillingEvent> cancellationMatchingBillingEvent;
|
Key<? extends BillingEvent> cancellationMatchingBillingEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link AllocationToken} used in the creation of this event, or null if one was not used.
|
||||||
|
*/
|
||||||
|
@Index @Nullable Key<AllocationToken> allocationToken;
|
||||||
|
|
||||||
public Money getCost() {
|
public Money getCost() {
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
@ -264,6 +270,10 @@ public abstract class BillingEvent extends ImmutableObject
|
||||||
return cancellationMatchingBillingEvent;
|
return cancellationMatchingBillingEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Key<AllocationToken>> getAllocationToken() {
|
||||||
|
return Optional.ofNullable(allocationToken);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder asBuilder() {
|
public Builder asBuilder() {
|
||||||
return new Builder(clone(this));
|
return new Builder(clone(this));
|
||||||
|
@ -306,6 +316,11 @@ public abstract class BillingEvent extends ImmutableObject
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setAllocationToken(@Nullable Key<AllocationToken> allocationToken) {
|
||||||
|
getInstance().allocationToken = allocationToken;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OneTime build() {
|
public OneTime build() {
|
||||||
OneTime instance = getInstance();
|
OneTime instance = getInstance();
|
||||||
|
|
|
@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.common.truth.Truth8.assertThat;
|
import static com.google.common.truth.Truth8.assertThat;
|
||||||
import static google.registry.flows.FlowTestCase.UserPrivileges.SUPERUSER;
|
import static google.registry.flows.FlowTestCase.UserPrivileges.SUPERUSER;
|
||||||
import static google.registry.model.billing.BillingEvent.Flag.ANCHOR_TENANT;
|
import static google.registry.model.billing.BillingEvent.Flag.ANCHOR_TENANT;
|
||||||
|
import static google.registry.model.billing.BillingEvent.Flag.RESERVED;
|
||||||
import static google.registry.model.billing.BillingEvent.Flag.SUNRISE;
|
import static google.registry.model.billing.BillingEvent.Flag.SUNRISE;
|
||||||
import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS;
|
import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS;
|
||||||
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
|
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
|
||||||
|
@ -151,6 +152,7 @@ import google.registry.model.reporting.HistoryEntry;
|
||||||
import google.registry.monitoring.whitebox.EppMetric;
|
import google.registry.monitoring.whitebox.EppMetric;
|
||||||
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
import google.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Duration;
|
import org.joda.time.Duration;
|
||||||
|
@ -162,6 +164,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
|
|
||||||
private static final String CLAIMS_KEY = "2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001";
|
private static final String CLAIMS_KEY = "2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001";
|
||||||
|
|
||||||
|
private AllocationToken allocationToken;
|
||||||
|
|
||||||
public DomainCreateFlowTest() {
|
public DomainCreateFlowTest() {
|
||||||
setEppInput("domain_create.xml", ImmutableMap.of("DOMAIN", "example.tld"));
|
setEppInput("domain_create.xml", ImmutableMap.of("DOMAIN", "example.tld"));
|
||||||
clock.setTo(DateTime.parse("1999-04-03T22:00:00.0Z").minus(Duration.millis(1)));
|
clock.setTo(DateTime.parse("1999-04-03T22:00:00.0Z").minus(Duration.millis(1)));
|
||||||
|
@ -170,12 +174,13 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
@Before
|
@Before
|
||||||
public void initCreateTest() {
|
public void initCreateTest() {
|
||||||
createTld("tld");
|
createTld("tld");
|
||||||
persistResource(
|
allocationToken =
|
||||||
new AllocationToken.Builder()
|
persistResource(
|
||||||
.setToken("abcDEF23456")
|
new AllocationToken.Builder()
|
||||||
.setTokenType(SINGLE_USE)
|
.setToken("abcDEF23456")
|
||||||
.setDomainName("anchor.tld")
|
.setTokenType(SINGLE_USE)
|
||||||
.build());
|
.setDomainName("anchor.tld")
|
||||||
|
.build());
|
||||||
persistResource(
|
persistResource(
|
||||||
Registry.get("tld")
|
Registry.get("tld")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -212,6 +217,14 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
|
|
||||||
private void assertSuccessfulCreate(
|
private void assertSuccessfulCreate(
|
||||||
String domainTld, ImmutableSet<BillingEvent.Flag> expectedBillingFlags) throws Exception {
|
String domainTld, ImmutableSet<BillingEvent.Flag> expectedBillingFlags) throws Exception {
|
||||||
|
assertSuccessfulCreate(domainTld, expectedBillingFlags, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertSuccessfulCreate(
|
||||||
|
String domainTld,
|
||||||
|
ImmutableSet<BillingEvent.Flag> expectedBillingFlags,
|
||||||
|
@Nullable AllocationToken allocationToken)
|
||||||
|
throws Exception {
|
||||||
DomainBase domain = reloadResourceByForeignKey();
|
DomainBase domain = reloadResourceByForeignKey();
|
||||||
|
|
||||||
boolean isAnchorTenant = expectedBillingFlags.contains(ANCHOR_TENANT);
|
boolean isAnchorTenant = expectedBillingFlags.contains(ANCHOR_TENANT);
|
||||||
|
@ -252,6 +265,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
.setBillingTime(billingTime)
|
.setBillingTime(billingTime)
|
||||||
.setFlags(expectedBillingFlags)
|
.setFlags(expectedBillingFlags)
|
||||||
.setParent(historyEntry)
|
.setParent(historyEntry)
|
||||||
|
.setAllocationToken(allocationToken == null ? null : Key.create(allocationToken))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
BillingEvent.Recurring renewBillingEvent =
|
BillingEvent.Recurring renewBillingEvent =
|
||||||
|
@ -440,7 +454,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
persistResource(
|
persistResource(
|
||||||
new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build());
|
new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build());
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
doSuccessfulTest();
|
runFlow();
|
||||||
|
assertSuccessfulCreate("tld", ImmutableSet.of(), token);
|
||||||
HistoryEntry historyEntry =
|
HistoryEntry historyEntry =
|
||||||
ofy().load().type(HistoryEntry.class).ancestor(reloadResourceByForeignKey()).first().now();
|
ofy().load().type(HistoryEntry.class).ancestor(reloadResourceByForeignKey()).first().now();
|
||||||
assertThat(ofy().load().entity(token).now().getRedemptionHistoryEntry())
|
assertThat(ofy().load().entity(token).now().getRedemptionHistoryEntry())
|
||||||
|
@ -451,10 +466,12 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
public void testSuccess_validAllocationToken_multiUse() throws Exception {
|
public void testSuccess_validAllocationToken_multiUse() throws Exception {
|
||||||
setEppInput("domain_create_allocationtoken.xml", ImmutableMap.of("DOMAIN", "example.tld"));
|
setEppInput("domain_create_allocationtoken.xml", ImmutableMap.of("DOMAIN", "example.tld"));
|
||||||
persistContactsAndHosts();
|
persistContactsAndHosts();
|
||||||
persistResource(
|
allocationToken =
|
||||||
new AllocationToken.Builder().setTokenType(UNLIMITED_USE).setToken("abc123").build());
|
persistResource(
|
||||||
|
new AllocationToken.Builder().setTokenType(UNLIMITED_USE).setToken("abc123").build());
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
doSuccessfulTest();
|
runFlow();
|
||||||
|
assertSuccessfulCreate("tld", ImmutableSet.of(), allocationToken);
|
||||||
clock.advanceOneMilli();
|
clock.advanceOneMilli();
|
||||||
setEppInput("domain_create_allocationtoken.xml", ImmutableMap.of("DOMAIN", "otherexample.tld"));
|
setEppInput("domain_create_allocationtoken.xml", ImmutableMap.of("DOMAIN", "otherexample.tld"));
|
||||||
runFlowAssertResponse(
|
runFlowAssertResponse(
|
||||||
|
@ -955,7 +972,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
setEppInput("domain_create_anchor_allocationtoken.xml");
|
setEppInput("domain_create_anchor_allocationtoken.xml");
|
||||||
persistContactsAndHosts();
|
persistContactsAndHosts();
|
||||||
runFlowAssertResponse(loadFile("domain_create_anchor_response.xml"));
|
runFlowAssertResponse(loadFile("domain_create_anchor_response.xml"));
|
||||||
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT));
|
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken);
|
||||||
assertNoLordn();
|
assertNoLordn();
|
||||||
assertAllocationTokenWasRedeemed("abcDEF23456");
|
assertAllocationTokenWasRedeemed("abcDEF23456");
|
||||||
}
|
}
|
||||||
|
@ -975,7 +992,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
setEppInput("domain_create_anchor_allocationtoken.xml");
|
setEppInput("domain_create_anchor_allocationtoken.xml");
|
||||||
persistContactsAndHosts();
|
persistContactsAndHosts();
|
||||||
runFlowAssertResponse(loadFile("domain_create_anchor_response.xml"));
|
runFlowAssertResponse(loadFile("domain_create_anchor_response.xml"));
|
||||||
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT));
|
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken);
|
||||||
assertNoLordn();
|
assertNoLordn();
|
||||||
assertAllocationTokenWasRedeemed("abcDEF23456");
|
assertAllocationTokenWasRedeemed("abcDEF23456");
|
||||||
}
|
}
|
||||||
|
@ -998,7 +1015,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z"));
|
clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z"));
|
||||||
persistContactsAndHosts();
|
persistContactsAndHosts();
|
||||||
runFlowAssertResponse(loadFile("domain_create_response_claims.xml"));
|
runFlowAssertResponse(loadFile("domain_create_response_claims.xml"));
|
||||||
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT));
|
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken);
|
||||||
assertDnsTasksEnqueued("example-one.tld");
|
assertDnsTasksEnqueued("example-one.tld");
|
||||||
assertClaimsLordn();
|
assertClaimsLordn();
|
||||||
assertAllocationTokenWasRedeemed("abcDEF23456");
|
assertAllocationTokenWasRedeemed("abcDEF23456");
|
||||||
|
@ -1029,12 +1046,13 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_anchorTenantInSunrise_withSignedMark() throws Exception {
|
public void testSuccess_anchorTenantInSunrise_withSignedMark() throws Exception {
|
||||||
persistResource(
|
allocationToken =
|
||||||
new AllocationToken.Builder()
|
persistResource(
|
||||||
.setDomainName("test-validate.tld")
|
new AllocationToken.Builder()
|
||||||
.setToken("abcDEF23456")
|
.setDomainName("test-validate.tld")
|
||||||
.setTokenType(SINGLE_USE)
|
.setToken("abcDEF23456")
|
||||||
.build());
|
.setTokenType(SINGLE_USE)
|
||||||
|
.build());
|
||||||
persistResource(
|
persistResource(
|
||||||
Registry.get("tld")
|
Registry.get("tld")
|
||||||
.asBuilder()
|
.asBuilder()
|
||||||
|
@ -1049,7 +1067,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
loadFile(
|
loadFile(
|
||||||
"domain_create_response_encoded_signed_mark_name.xml",
|
"domain_create_response_encoded_signed_mark_name.xml",
|
||||||
ImmutableMap.of("DOMAIN", "test-validate.tld")));
|
ImmutableMap.of("DOMAIN", "test-validate.tld")));
|
||||||
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT, SUNRISE));
|
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT, SUNRISE), allocationToken);
|
||||||
assertDnsTasksEnqueued("test-validate.tld");
|
assertDnsTasksEnqueued("test-validate.tld");
|
||||||
assertSunriseLordn("test-validate.tld");
|
assertSunriseLordn("test-validate.tld");
|
||||||
assertAllocationTokenWasRedeemed("abcDEF23456");
|
assertAllocationTokenWasRedeemed("abcDEF23456");
|
||||||
|
@ -1057,19 +1075,20 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess_reservedDomain_viaAllocationTokenExtension() throws Exception {
|
public void testSuccess_reservedDomain_viaAllocationTokenExtension() throws Exception {
|
||||||
persistResource(
|
allocationToken =
|
||||||
new AllocationToken.Builder()
|
persistResource(
|
||||||
.setToken("abc123")
|
new AllocationToken.Builder()
|
||||||
.setTokenType(SINGLE_USE)
|
.setToken("abc123")
|
||||||
.setDomainName("resdom.tld")
|
.setTokenType(SINGLE_USE)
|
||||||
.build());
|
.setDomainName("resdom.tld")
|
||||||
|
.build());
|
||||||
// Despite the domain being FULLY_BLOCKED, the non-superuser create succeeds the domain is also
|
// 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.
|
// RESERVED_FOR_SPECIFIC_USE and the correct allocation token is passed.
|
||||||
setEppInput("domain_create_allocationtoken.xml", ImmutableMap.of("DOMAIN", "resdom.tld"));
|
setEppInput("domain_create_allocationtoken.xml", ImmutableMap.of("DOMAIN", "resdom.tld"));
|
||||||
persistContactsAndHosts();
|
persistContactsAndHosts();
|
||||||
runFlowAssertResponse(
|
runFlowAssertResponse(
|
||||||
loadFile("domain_create_response.xml", ImmutableMap.of("DOMAIN", "resdom.tld")));
|
loadFile("domain_create_response.xml", ImmutableMap.of("DOMAIN", "resdom.tld")));
|
||||||
assertSuccessfulCreate("tld", ImmutableSet.of(Flag.RESERVED));
|
assertSuccessfulCreate("tld", ImmutableSet.of(RESERVED), allocationToken);
|
||||||
assertNoLordn();
|
assertNoLordn();
|
||||||
assertAllocationTokenWasRedeemed("abc123");
|
assertAllocationTokenWasRedeemed("abc123");
|
||||||
}
|
}
|
||||||
|
@ -1088,7 +1107,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
persistContactsAndHosts();
|
persistContactsAndHosts();
|
||||||
runFlowAssertResponse(
|
runFlowAssertResponse(
|
||||||
CommitMode.LIVE, SUPERUSER, loadFile("domain_create_reserved_response.xml"));
|
CommitMode.LIVE, SUPERUSER, loadFile("domain_create_reserved_response.xml"));
|
||||||
assertSuccessfulCreate("tld", ImmutableSet.of(Flag.RESERVED));
|
assertSuccessfulCreate("tld", ImmutableSet.of(RESERVED));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1643,7 +1662,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
loadFile(
|
loadFile(
|
||||||
"domain_create_response_encoded_signed_mark_name.xml",
|
"domain_create_response_encoded_signed_mark_name.xml",
|
||||||
ImmutableMap.of("DOMAIN", "test-validate.tld")));
|
ImmutableMap.of("DOMAIN", "test-validate.tld")));
|
||||||
assertSuccessfulCreate("tld", ImmutableSet.of(Flag.SUNRISE));
|
assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE));
|
||||||
assertSunriseLordn("test-validate.tld");
|
assertSunriseLordn("test-validate.tld");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1661,7 +1680,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
loadFile(
|
loadFile(
|
||||||
"domain_create_response_encoded_signed_mark_name.xml",
|
"domain_create_response_encoded_signed_mark_name.xml",
|
||||||
ImmutableMap.of("DOMAIN", "test-validate.tld")));
|
ImmutableMap.of("DOMAIN", "test-validate.tld")));
|
||||||
assertSuccessfulCreate("tld", ImmutableSet.of(Flag.SUNRISE));
|
assertSuccessfulCreate("tld", ImmutableSet.of(SUNRISE));
|
||||||
assertSunriseLordn("test-validate.tld");
|
assertSunriseLordn("test-validate.tld");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package google.registry.model.billing;
|
package google.registry.model.billing;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.testing.DatastoreHelper.createTld;
|
import static google.registry.testing.DatastoreHelper.createTld;
|
||||||
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
|
||||||
|
@ -25,6 +26,7 @@ import static org.joda.money.CurrencyUnit.USD;
|
||||||
import static org.joda.time.DateTimeZone.UTC;
|
import static org.joda.time.DateTimeZone.UTC;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.ImmutableSortedMap;
|
||||||
import com.googlecode.objectify.Key;
|
import com.googlecode.objectify.Key;
|
||||||
import google.registry.model.EntityTestCase;
|
import google.registry.model.EntityTestCase;
|
||||||
import google.registry.model.billing.BillingEvent.Flag;
|
import google.registry.model.billing.BillingEvent.Flag;
|
||||||
|
@ -32,7 +34,10 @@ import google.registry.model.billing.BillingEvent.Reason;
|
||||||
import google.registry.model.domain.DomainBase;
|
import google.registry.model.domain.DomainBase;
|
||||||
import google.registry.model.domain.GracePeriod;
|
import google.registry.model.domain.GracePeriod;
|
||||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||||
|
import google.registry.model.domain.token.AllocationToken;
|
||||||
|
import google.registry.model.domain.token.AllocationToken.TokenStatus;
|
||||||
import google.registry.model.reporting.HistoryEntry;
|
import google.registry.model.reporting.HistoryEntry;
|
||||||
|
import google.registry.util.DateTimeUtils;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -67,22 +72,41 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
.setModificationTime(now.plusDays(1))
|
.setModificationTime(now.plusDays(1))
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
oneTime = persistResource(commonInit(
|
AllocationToken allocationToken =
|
||||||
new BillingEvent.OneTime.Builder()
|
persistResource(
|
||||||
.setParent(historyEntry)
|
new AllocationToken.Builder()
|
||||||
.setReason(Reason.CREATE)
|
.setToken("abc123")
|
||||||
.setFlags(ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT))
|
.setTokenType(UNLIMITED_USE)
|
||||||
.setPeriodYears(2)
|
.setDiscountFraction(0.5)
|
||||||
.setCost(Money.of(USD, 1))
|
.setTokenStatusTransitions(
|
||||||
.setEventTime(now)
|
ImmutableSortedMap.<DateTime, TokenStatus>naturalOrder()
|
||||||
.setBillingTime(now.plusDays(5))));
|
.put(DateTimeUtils.START_OF_TIME, TokenStatus.NOT_STARTED)
|
||||||
recurring = persistResource(commonInit(
|
.put(DateTime.now(UTC), TokenStatus.VALID)
|
||||||
new BillingEvent.Recurring.Builder()
|
.put(DateTime.now(UTC).plusWeeks(8), TokenStatus.ENDED)
|
||||||
.setParent(historyEntry)
|
.build())
|
||||||
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
.build());
|
||||||
.setReason(Reason.RENEW)
|
|
||||||
.setEventTime(now.plusYears(1))
|
oneTime =
|
||||||
.setRecurrenceEndTime(END_OF_TIME)));
|
persistResource(
|
||||||
|
commonInit(
|
||||||
|
new BillingEvent.OneTime.Builder()
|
||||||
|
.setParent(historyEntry)
|
||||||
|
.setReason(Reason.CREATE)
|
||||||
|
.setFlags(ImmutableSet.of(BillingEvent.Flag.ANCHOR_TENANT))
|
||||||
|
.setPeriodYears(2)
|
||||||
|
.setCost(Money.of(USD, 1))
|
||||||
|
.setEventTime(now)
|
||||||
|
.setBillingTime(now.plusDays(5))
|
||||||
|
.setAllocationToken(Key.create(allocationToken))));
|
||||||
|
recurring =
|
||||||
|
persistResource(
|
||||||
|
commonInit(
|
||||||
|
new BillingEvent.Recurring.Builder()
|
||||||
|
.setParent(historyEntry)
|
||||||
|
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
||||||
|
.setReason(Reason.RENEW)
|
||||||
|
.setEventTime(now.plusYears(1))
|
||||||
|
.setRecurrenceEndTime(END_OF_TIME)));
|
||||||
oneTimeSynthetic = persistResource(commonInit(
|
oneTimeSynthetic = persistResource(commonInit(
|
||||||
new BillingEvent.OneTime.Builder()
|
new BillingEvent.OneTime.Builder()
|
||||||
.setParent(historyEntry)
|
.setParent(historyEntry)
|
||||||
|
@ -166,9 +190,20 @@ public class BillingEventTest extends EntityTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIndexing() throws Exception {
|
public void testIndexing() throws Exception {
|
||||||
verifyIndexing(oneTime, "clientId", "eventTime", "billingTime", "syntheticCreationTime");
|
|
||||||
verifyIndexing(
|
verifyIndexing(
|
||||||
oneTimeSynthetic, "clientId", "eventTime", "billingTime", "syntheticCreationTime");
|
oneTime,
|
||||||
|
"clientId",
|
||||||
|
"eventTime",
|
||||||
|
"billingTime",
|
||||||
|
"syntheticCreationTime",
|
||||||
|
"allocationToken");
|
||||||
|
verifyIndexing(
|
||||||
|
oneTimeSynthetic,
|
||||||
|
"clientId",
|
||||||
|
"eventTime",
|
||||||
|
"billingTime",
|
||||||
|
"syntheticCreationTime",
|
||||||
|
"allocationToken");
|
||||||
verifyIndexing(
|
verifyIndexing(
|
||||||
recurring, "clientId", "eventTime", "recurrenceEndTime", "recurrenceTimeOfYear.timeString");
|
recurring, "clientId", "eventTime", "recurrenceEndTime", "recurrenceTimeOfYear.timeString");
|
||||||
verifyIndexing(cancellationOneTime, "clientId", "eventTime", "billingTime");
|
verifyIndexing(cancellationOneTime, "clientId", "eventTime", "billingTime");
|
||||||
|
|
|
@ -41,6 +41,7 @@ class google.registry.model.billing.BillingEvent$OneTime {
|
||||||
@Id long id;
|
@Id long id;
|
||||||
@Parent com.googlecode.objectify.Key<google.registry.model.reporting.HistoryEntry> parent;
|
@Parent com.googlecode.objectify.Key<google.registry.model.reporting.HistoryEntry> parent;
|
||||||
com.googlecode.objectify.Key<? extends google.registry.model.billing.BillingEvent> cancellationMatchingBillingEvent;
|
com.googlecode.objectify.Key<? extends google.registry.model.billing.BillingEvent> cancellationMatchingBillingEvent;
|
||||||
|
com.googlecode.objectify.Key<google.registry.model.domain.token.AllocationToken> allocationToken;
|
||||||
google.registry.model.billing.BillingEvent$Reason reason;
|
google.registry.model.billing.BillingEvent$Reason reason;
|
||||||
java.lang.Integer periodYears;
|
java.lang.Integer periodYears;
|
||||||
java.lang.String clientId;
|
java.lang.String clientId;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue