Rename LrpToken to LrpTokenEntity

This is to better distinguish between an LRP "token" (the string passed along in EPP) and the datastore entity that contains the token and all metadata.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=135943480
This commit is contained in:
ctingue 2016-10-12 11:52:27 -07:00 committed by Ben McIlwain
parent 1a9f91ed9e
commit dd9137fbd1
14 changed files with 104 additions and 97 deletions

View file

@ -12,7 +12,7 @@ ForeignKeyHostIndex
HistoryEntry
HostResource
LogsExportCursor
LrpToken
LrpTokenEntity
Modification
OneTime
PollMessage

View file

@ -104,7 +104,7 @@ import google.registry.flows.domain.DomainFlowUtils.TrailingDashException;
import google.registry.flows.domain.DomainFlowUtils.UnsupportedFeeAttributeException;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.LrpToken;
import google.registry.model.domain.LrpTokenEntity;
import google.registry.model.domain.launch.ApplicationStatus;
import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.launch.LaunchPhase;
@ -878,11 +878,12 @@ public class DomainApplicationCreateFlowTest
persistResource(Registry.get("tld").asBuilder()
.setLrpTldStates(ImmutableSet.of(TldState.LANDRUSH))
.build());
LrpToken token = persistResource(new LrpToken.Builder()
.setToken("lrptokentest")
.setAssignee("test-validate.tld")
.setValidTlds(ImmutableSet.of("tld"))
.build());
LrpTokenEntity token = persistResource(
new LrpTokenEntity.Builder()
.setToken("lrptokentest")
.setAssignee("test-validate.tld")
.setValidTlds(ImmutableSet.of("tld"))
.build());
setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
@ -910,11 +911,12 @@ public class DomainApplicationCreateFlowTest
persistResource(Registry.get("tld").asBuilder()
.setLrpTldStates(ImmutableSet.of(TldState.LANDRUSH))
.build());
LrpToken token = persistResource(new LrpToken.Builder()
.setToken("lrptokentest")
.setAssignee("test-validate.tld")
.setValidTlds(ImmutableSet.of("tld"))
.build());
LrpTokenEntity token = persistResource(
new LrpTokenEntity.Builder()
.setToken("lrptokentest")
.setAssignee("test-validate.tld")
.setValidTlds(ImmutableSet.of("tld"))
.build());
setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
@ -928,7 +930,7 @@ public class DomainApplicationCreateFlowTest
persistResource(Registry.get("tld").asBuilder()
.setLrpTldStates(ImmutableSet.of(TldState.LANDRUSH))
.build());
persistResource(new LrpToken.Builder()
persistResource(new LrpTokenEntity.Builder()
.setToken("lrptokentest2")
.setAssignee("test-validate.tld")
.setValidTlds(ImmutableSet.of("tld"))
@ -946,7 +948,7 @@ public class DomainApplicationCreateFlowTest
persistResource(Registry.get("tld").asBuilder()
.setLrpTldStates(ImmutableSet.of(TldState.LANDRUSH))
.build());
persistResource(new LrpToken.Builder()
persistResource(new LrpTokenEntity.Builder()
.setToken("lrptokentest")
// The below assignee doesn't really make sense here, but as of right now the validation
// in TldSpecificLogicProxy is just a match on the domain name, so this test ensures that
@ -967,11 +969,12 @@ public class DomainApplicationCreateFlowTest
persistResource(Registry.get("tld").asBuilder()
.setLrpTldStates(ImmutableSet.of(TldState.LANDRUSH))
.build());
persistResource(new LrpToken.Builder()
persistResource(new LrpTokenEntity.Builder()
.setToken("lrptokentest")
.setAssignee("test-validate.tld")
.setValidTlds(ImmutableSet.of("tld"))
.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, "1")) // as long as it's not null
.setRedemptionHistoryEntry(
Key.create(HistoryEntry.class, "1")) // as long as it's not null
.build());
setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts();
@ -983,11 +986,13 @@ public class DomainApplicationCreateFlowTest
@Test
public void testSuccess_landrushApplicationWithLrpToken_notInLrp() throws Exception {
createTld("tld", TldState.LANDRUSH);
LrpToken token = persistResource(new LrpToken.Builder()
.setToken("lrptokentest")
.setAssignee("test-validate.tld")
.setValidTlds(ImmutableSet.of("tld"))
.build());
LrpTokenEntity token =
persistResource(
new LrpTokenEntity.Builder()
.setToken("lrptokentest")
.setAssignee("test-validate.tld")
.setValidTlds(ImmutableSet.of("tld"))
.build());
setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
@ -1006,11 +1011,12 @@ public class DomainApplicationCreateFlowTest
START_OF_TIME, TldState.SUNRISE,
clock.nowUtc(), TldState.LANDRUSH))
.build());
LrpToken token = persistResource(new LrpToken.Builder()
.setToken("lrptokentest")
.setAssignee("test-validate.tld")
.setValidTlds(ImmutableSet.of("tld"))
.build());
LrpTokenEntity token = persistResource(
new LrpTokenEntity.Builder()
.setToken("lrptokentest")
.setAssignee("test-validate.tld")
.setValidTlds(ImmutableSet.of("tld"))
.build());
setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts();
clock.advanceOneMilli();

View file

@ -103,7 +103,7 @@ import google.registry.model.billing.BillingEvent.Flag;
import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.LrpToken;
import google.registry.model.domain.LrpTokenEntity;
import google.registry.model.domain.TestExtraLogicManager;
import google.registry.model.domain.TestExtraLogicManager.TestExtraLogicManagerSuccessException;
import google.registry.model.domain.launch.ApplicationStatus;
@ -823,7 +823,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
"tld-reserved",
"anchor,RESERVED_FOR_ANCHOR_TENANT,2fooBAR"))
.build());
LrpToken token = persistResource(new LrpToken.Builder()
LrpTokenEntity token = persistResource(new LrpTokenEntity.Builder()
.setToken("2fooBAR")
.setAssignee("anchor.tld")
.build());

View file

@ -30,11 +30,11 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
/** Unit tests for {@link LrpToken}. */
public class LrpTokenTest extends EntityTestCase {
/** Unit tests for {@link LrpTokenEntity}. */
public class LrpTokenEntityTest extends EntityTestCase {
LrpToken unredeemedToken;
LrpToken redeemedToken;
LrpTokenEntity unredeemedToken;
LrpTokenEntity redeemedToken;
@Rule
public final ExceptionRule thrown = new ExceptionRule();
@ -48,18 +48,17 @@ public class LrpTokenTest extends EntityTestCase {
.setType(HistoryEntry.Type.DOMAIN_APPLICATION_CREATE)
.build());
unredeemedToken = persistResource(
new LrpToken.Builder()
new LrpTokenEntity.Builder()
.setAssignee("1:1020304")
.setToken("a0b1c2d3e4f5g6")
.setValidTlds(ImmutableSet.of("tld"))
.setMetadata(ImmutableMap.of("foo", "bar"))
.build());
redeemedToken = persistResource(
new LrpToken.Builder()
new LrpTokenEntity.Builder()
.setAssignee("2:org.testdomain")
.setToken("h0i1j2k3l4m")
.setRedemptionHistoryEntry(
Key.create(applicationCreateHistoryEntry))
.setRedemptionHistoryEntry(Key.create(applicationCreateHistoryEntry))
.setValidTlds(ImmutableSet.of("tld"))
.setMetadata(ImmutableMap.of("bar", "foo"))
.build());
@ -72,13 +71,14 @@ public class LrpTokenTest extends EntityTestCase {
@Test
public void testSuccess_loadByToken() throws Exception {
assertThat(ofy().load().key(Key.create(LrpToken.class, "a0b1c2d3e4f5g6")).now())
assertThat(ofy().load().key(Key.create(LrpTokenEntity.class, "a0b1c2d3e4f5g6")).now())
.isEqualTo(unredeemedToken);
}
@Test
public void testSuccess_loadByAssignee() throws Exception {
assertThat(ofy().load().type(LrpToken.class).filter("assignee", "1:1020304").first().now())
assertThat(
ofy().load().type(LrpTokenEntity.class).filter("assignee", "1:1020304").first().now())
.isEqualTo(unredeemedToken);
}
@Test

View file

@ -286,7 +286,7 @@ class google.registry.model.domain.GracePeriod {
java.lang.String clientId;
org.joda.time.DateTime expirationTime;
}
class google.registry.model.domain.LrpToken {
class google.registry.model.domain.LrpTokenEntity {
@Id java.lang.String token;
com.googlecode.objectify.Key<google.registry.model.reporting.HistoryEntry> redemptionHistoryEntry;
google.registry.model.UpdateAutoTimestamp updateTimestamp;

View file

@ -24,7 +24,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
import com.googlecode.objectify.Key;
import google.registry.model.domain.LrpToken;
import google.registry.model.domain.LrpTokenEntity;
import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.DeterministicStringGenerator;
import google.registry.testing.DeterministicStringGenerator.Rule;
@ -61,7 +61,7 @@ public class CreateLrpTokensCommandTest extends CommandTestCase<CreateLrpTokensC
@Test
public void testSuccess_oneAssignee_tokenCollision() throws Exception {
LrpToken existingToken = persistResource(new LrpToken.Builder()
LrpTokenEntity existingToken = persistResource(new LrpTokenEntity.Builder()
.setToken("LRP_abcdefghijklmnop")
.setAssignee("otherdomain.tld")
.setValidTlds(ImmutableSet.of("tld"))
@ -120,7 +120,7 @@ public class CreateLrpTokensCommandTest extends CommandTestCase<CreateLrpTokensC
@Test
public void testSuccess_largeFile() throws Exception {
int numberOfTokens = 67;
LrpToken[] expectedTokens = new LrpToken[numberOfTokens];
LrpTokenEntity[] expectedTokens = new LrpTokenEntity[numberOfTokens];
// Prepend a counter to avoid collisions, 16-char alphabet will always generate the same string.
stringGenerator =
new DeterministicStringGenerator("abcdefghijklmnop", Rule.PREPEND_COUNTER);
@ -165,18 +165,19 @@ public class CreateLrpTokensCommandTest extends CommandTestCase<CreateLrpTokensC
runCommand("--assignee=domain.tld", "--tlds=foo");
}
private void assertLrpTokens(LrpToken... expected) throws Exception {
private void assertLrpTokens(LrpTokenEntity... expected) throws Exception {
// Using ImmutableObject comparison here is tricky because updateTimestamp is not set on the
// expected LrpToken objects and will cause the assert to fail.
Iterable<LrpToken> actual = ofy().load().type(LrpToken.class);
ImmutableMap.Builder<String, LrpToken> actualTokenMapBuilder = new ImmutableMap.Builder<>();
for (LrpToken token : actual) {
Iterable<LrpTokenEntity> actual = ofy().load().type(LrpTokenEntity.class);
ImmutableMap.Builder<String, LrpTokenEntity> actualTokenMapBuilder =
new ImmutableMap.Builder<>();
for (LrpTokenEntity token : actual) {
actualTokenMapBuilder.put(token.getToken(), token);
}
ImmutableMap<String, LrpToken> actualTokenMap = actualTokenMapBuilder.build();
ImmutableMap<String, LrpTokenEntity> actualTokenMap = actualTokenMapBuilder.build();
assertThat(actualTokenMap).hasSize(expected.length);
for (LrpToken expectedToken : expected) {
LrpToken match = actualTokenMap.get(expectedToken.getToken());
for (LrpTokenEntity expectedToken : expected) {
LrpTokenEntity match = actualTokenMap.get(expectedToken.getToken());
assertThat(match).isNotNull();
assertThat(match.getAssignee()).isEqualTo(expectedToken.getAssignee());
assertThat(match.getValidTlds()).containsExactlyElementsIn(expectedToken.getValidTlds());
@ -185,12 +186,12 @@ public class CreateLrpTokensCommandTest extends CommandTestCase<CreateLrpTokensC
}
}
private LrpToken createToken(
private LrpTokenEntity createToken(
String token,
String assignee,
Set<String> validTlds,
@Nullable Key<HistoryEntry> redemptionHistoryEntry) {
LrpToken.Builder tokenBuilder = new LrpToken.Builder()
LrpTokenEntity.Builder tokenBuilder = new LrpTokenEntity.Builder()
.setAssignee(assignee)
.setValidTlds(validTlds)
.setToken(token);

View file

@ -20,7 +20,7 @@ import static google.registry.testing.DatastoreHelper.persistResource;
import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.LrpToken;
import google.registry.model.domain.LrpTokenEntity;
import google.registry.model.reporting.HistoryEntry;
import org.junit.Before;
import org.junit.Test;
@ -37,7 +37,7 @@ public class GetLrpTokenCommandTest extends CommandTestCase<GetLrpTokenCommand>
.setType(HistoryEntry.Type.DOMAIN_APPLICATION_CREATE)
.build());
persistResource(
new LrpToken.Builder()
new LrpTokenEntity.Builder()
.setAssignee("domain.tld")
.setToken("domain_token")
.setRedemptionHistoryEntry(Key.create(applicationCreateHistoryEntry))