Make code change for AllocationToken schema change (#1581)

* Make code change for AllocationToken schema change
This commit is contained in:
Rachel Guan 2022-04-15 15:28:39 -04:00 committed by GitHub
parent 98461c1875
commit 94017b694e
4 changed files with 63 additions and 0 deletions

View file

@ -43,6 +43,7 @@ import google.registry.model.BackupGroupRoot;
import google.registry.model.Buildable;
import google.registry.model.CreateAutoTimestamp;
import google.registry.model.annotations.ReportedOn;
import google.registry.model.billing.BillingEvent.RenewalPriceBehavior;
import google.registry.model.common.TimedTransitionProperty;
import google.registry.model.common.TimedTransitionProperty.TimeMapper;
import google.registry.model.common.TimedTransitionProperty.TimedTransition;
@ -151,6 +152,10 @@ public class AllocationToken extends BackupGroupRoot implements Buildable, Datas
@Enumerated(EnumType.STRING)
TokenType tokenType;
@Enumerated(EnumType.STRING)
@Column(name = "renewalPriceBehavior", nullable = false)
RenewalPriceBehavior renewalPriceBehavior = RenewalPriceBehavior.DEFAULT;
// TODO: Remove onLoad once all allocation tokens are migrated to have a discountYears of 1.
@OnLoad
void onLoad() {
@ -240,6 +245,10 @@ public class AllocationToken extends BackupGroupRoot implements Buildable, Datas
return tokenStatusTransitions;
}
public RenewalPriceBehavior getRenewalPriceBehavior() {
return renewalPriceBehavior;
}
public VKey<AllocationToken> createVKey() {
return VKey.create(AllocationToken.class, getToken(), Key.create(this));
}
@ -362,5 +371,10 @@ public class AllocationToken extends BackupGroupRoot implements Buildable, Datas
"tokenStatusTransitions must start with NOT_STARTED");
return this;
}
public Builder setRenewalPriceBehavior(RenewalPriceBehavior renewalPriceBehavior) {
getInstance().renewalPriceBehavior = renewalPriceBehavior;
return this;
}
}
}

View file

@ -34,6 +34,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.googlecode.objectify.Key;
import google.registry.model.EntityTestCase;
import google.registry.model.billing.BillingEvent.RenewalPriceBehavior;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.token.AllocationToken.TokenStatus;
import google.registry.model.domain.token.AllocationToken.TokenType;
@ -160,6 +161,52 @@ public class AllocationTokenTest extends EntityTestCase {
assertThat(tokenAfterPersisting.getCreationTime()).hasValue(fakeClock.nowUtc());
}
@TestOfyAndSql
void testgetRenewalBehavior_returnsDefaultRenewBehavior() {
assertThat(
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(SINGLE_USE)
.build())
.getRenewalPriceBehavior())
.isEqualTo(RenewalPriceBehavior.DEFAULT);
}
@TestOfyAndSql
void testsetRenewalBehavior_assertsRenewalBehaviorIsNotDefault() {
assertThat(
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(SINGLE_USE)
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.build())
.getRenewalPriceBehavior())
.isEqualTo(RenewalPriceBehavior.SPECIFIED);
}
@TestOfyAndSql
void testsetRenewalBehavior_assertRenewalBehaviorIsModified() {
AllocationToken token =
persistResource(
new AllocationToken.Builder()
.setToken("abc123")
.setTokenType(SINGLE_USE)
.setRenewalPriceBehavior(RenewalPriceBehavior.NONPREMIUM)
.build());
AllocationToken loadedToken = loadByEntity(token);
assertThat(token).isEqualTo(loadedToken);
AllocationToken modifiedToken =
persistResource(
loadedToken
.asBuilder()
.setRenewalPriceBehavior(RenewalPriceBehavior.SPECIFIED)
.build());
assertThat(loadByEntity(token).getRenewalPriceBehavior())
.isEqualTo(RenewalPriceBehavior.SPECIFIED);
}
@TestOfyAndSql
void testSetCreationTime_cantCallMoreThanOnce() {
AllocationToken.Builder builder =

View file

@ -350,6 +350,7 @@ class google.registry.model.domain.token.AllocationToken {
double discountFraction;
google.registry.model.CreateAutoTimestamp creationTime;
google.registry.model.UpdateAutoTimestamp updateTimestamp;
google.registry.model.billing.BillingEvent$RenewalPriceBehavior renewalPriceBehavior;
google.registry.model.common.TimedTransitionProperty<google.registry.model.domain.token.AllocationToken$TokenStatus, google.registry.model.domain.token.AllocationToken$TokenStatusTransition> tokenStatusTransitions;
google.registry.model.domain.token.AllocationToken$TokenType tokenType;
google.registry.persistence.DomainHistoryVKey redemptionHistoryEntry;

View file

@ -24,6 +24,7 @@
domain_name text,
redemption_domain_history_id int8,
redemption_domain_repo_id text,
renewal_price_behavior text not null,
token_status_transitions hstore,
token_type text,
primary key (token)