Convert all VKeys to symmetric VKeys (#641)

* Convert hosts to symmetric VKey

* Convert ContactResource to symmetric VKeys

* Convert BillingEvents to symmetric VKeys

* Converted PollMessage to symmetric VKeys

* Convert AllocationToken to symmetric VKeys

* Remove static methods, get everything working

* Changes requested in review.

* Removed newly introduced createOfy() calls
This commit is contained in:
Michael Muller 2020-06-24 08:02:11 -04:00 committed by GitHub
parent 11ec4d64f2
commit c9d4ffb233
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 181 additions and 101 deletions

View file

@ -340,8 +340,7 @@ public class EppTestCase extends ShardableTestCase {
.setTargetId(domain.getDomainName())
.setClientId(domain.getCurrentSponsorClientId())
.setEventTime(deleteTime)
.setOneTimeEventKey(
VKey.createOfy(OneTime.class, findKeyToActualOneTimeBillingEvent(billingEventToCancel)))
.setOneTimeEventKey(VKey.from(findKeyToActualOneTimeBillingEvent(billingEventToCancel)))
.setBillingTime(createTime.plus(Registry.get(domain.getTld()).getAddGracePeriodLength()))
.setReason(Reason.CREATE)
.setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_DELETE))
@ -355,8 +354,7 @@ public class EppTestCase extends ShardableTestCase {
.setTargetId(domain.getDomainName())
.setClientId(domain.getCurrentSponsorClientId())
.setEventTime(deleteTime)
.setOneTimeEventKey(
VKey.createOfy(OneTime.class, findKeyToActualOneTimeBillingEvent(billingEventToCancel)))
.setOneTimeEventKey(VKey.from(findKeyToActualOneTimeBillingEvent(billingEventToCancel)))
.setBillingTime(renewTime.plus(Registry.get(domain.getTld()).getRenewGracePeriodLength()))
.setReason(Reason.RENEW)
.setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_DELETE))

View file

@ -403,8 +403,7 @@ public class DomainTransferApproveFlowTest
.setEventTime(clock.nowUtc()) // The cancellation happens at the moment of transfer.
.setBillingTime(
oldExpirationTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength()))
.setRecurringEventKey(
VKey.createOfy(BillingEvent.Recurring.class, domain.getAutorenewBillingEvent())));
.setRecurringEventKey(VKey.from(domain.getAutorenewBillingEvent())));
}
@Test

View file

@ -1144,8 +1144,7 @@ public class DomainTransferRequestFlowTest
.setEventTime(clock.nowUtc().plus(Registry.get("tld").getAutomaticTransferLength()))
.setBillingTime(autorenewTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength()))
// The cancellation should refer to the old autorenew billing event.
.setRecurringEventKey(
VKey.createOfy(BillingEvent.Recurring.class, existingAutorenewEvent)));
.setRecurringEventKey(VKey.from(existingAutorenewEvent)));
}
@Test
@ -1173,8 +1172,7 @@ public class DomainTransferRequestFlowTest
.setBillingTime(
expirationTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength()))
// The cancellation should refer to the old autorenew billing event.
.setRecurringEventKey(
VKey.createOfy(BillingEvent.Recurring.class, existingAutorenewEvent)));
.setRecurringEventKey(VKey.from(existingAutorenewEvent)));
}
@Test

View file

@ -113,7 +113,7 @@ public class ContactResourceTest extends EntityTestCase {
.setLosingClientId("losing")
.setPendingTransferExpirationTime(fakeClock.nowUtc())
.setServerApproveEntities(
ImmutableSet.of(VKey.createOfy(BillingEvent.OneTime.class, 1)))
ImmutableSet.of(VKey.create(BillingEvent.OneTime.class, 1)))
.setTransferRequestTime(fakeClock.nowUtc())
.setTransferStatus(TransferStatus.SERVER_APPROVED)
.setTransferRequestTrid(Trid.create("client-trid", "server-trid"))

View file

@ -76,7 +76,7 @@ public class DomainBaseTest extends EntityTestCase {
persistResource(
new HostResource.Builder()
.setHostName("ns1.example.com")
.setSuperordinateDomain(VKey.createOfy(DomainBase.class, domainKey))
.setSuperordinateDomain(VKey.from(domainKey))
.setRepoId("1-COM")
.build())
.createVKey();
@ -139,15 +139,12 @@ public class DomainBaseTest extends EntityTestCase {
.setPendingTransferExpirationTime(fakeClock.nowUtc())
.setServerApproveEntities(
ImmutableSet.of(
VKey.createOfy(BillingEvent.OneTime.class, oneTimeBillKey),
VKey.createOfy(BillingEvent.Recurring.class, recurringBillKey),
VKey.createOfy(PollMessage.Autorenew.class, autorenewPollKey)))
.setServerApproveBillingEvent(
VKey.createOfy(BillingEvent.OneTime.class, oneTimeBillKey))
.setServerApproveAutorenewEvent(
VKey.createOfy(BillingEvent.Recurring.class, recurringBillKey))
.setServerApproveAutorenewPollMessage(
VKey.createOfy(PollMessage.Autorenew.class, autorenewPollKey))
VKey.from(oneTimeBillKey),
VKey.from(recurringBillKey),
VKey.from(autorenewPollKey)))
.setServerApproveBillingEvent(VKey.from(oneTimeBillKey))
.setServerApproveAutorenewEvent(VKey.from(recurringBillKey))
.setServerApproveAutorenewPollMessage(VKey.from(autorenewPollKey))
.setTransferRequestTime(fakeClock.nowUtc().plusDays(1))
.setTransferStatus(TransferStatus.SERVER_APPROVED)
.setTransferRequestTrid(Trid.create("client-trid", "server-trid"))
@ -750,10 +747,8 @@ public class DomainBaseTest extends EntityTestCase {
.setPendingTransferExpirationTime(transferExpirationTime)
.setTransferStatus(TransferStatus.PENDING)
.setGainingClientId("TheRegistrar")
.setServerApproveAutorenewEvent(
VKey.createOfy(BillingEvent.Recurring.class, recurringBillKey))
.setServerApproveBillingEvent(
VKey.createOfy(BillingEvent.OneTime.class, oneTimeBillKey))
.setServerApproveAutorenewEvent(VKey.from(recurringBillKey))
.setServerApproveBillingEvent(VKey.from(oneTimeBillKey))
.build();
domain =
persistResource(

View file

@ -63,7 +63,7 @@ public class HostResourceTest extends EntityTestCase {
.setLosingClientId("losing")
.setPendingTransferExpirationTime(fakeClock.nowUtc())
.setServerApproveEntities(
ImmutableSet.of(VKey.createOfy(BillingEvent.OneTime.class, 1)))
ImmutableSet.of(VKey.create(BillingEvent.OneTime.class, 1)))
.setTransferRequestTime(fakeClock.nowUtc())
.setTransferStatus(TransferStatus.SERVER_APPROVED)
.setTransferRequestTrid(Trid.create("client-trid", "server-trid"))

View file

@ -48,11 +48,11 @@ public class TransferDataTest {
@Before
public void setUp() {
transferBillingEventKey = VKey.createOfy(BillingEvent.OneTime.class, 12345);
otherServerApproveBillingEventKey = VKey.createOfy(BillingEvent.Cancellation.class, 2468);
recurringBillingEventKey = VKey.createOfy(BillingEvent.Recurring.class, 13579);
autorenewPollMessageKey = VKey.createOfy(PollMessage.Autorenew.class, 67890);
otherServerApprovePollMessageKey = VKey.createOfy(PollMessage.OneTime.class, 314159);
transferBillingEventKey = VKey.create(BillingEvent.OneTime.class, 12345);
otherServerApproveBillingEventKey = VKey.create(BillingEvent.Cancellation.class, 2468);
recurringBillingEventKey = VKey.create(BillingEvent.Recurring.class, 13579);
autorenewPollMessageKey = VKey.create(PollMessage.Autorenew.class, 67890);
otherServerApprovePollMessageKey = VKey.create(PollMessage.OneTime.class, 314159);
}
@Test

View file

@ -17,10 +17,13 @@ package google.registry.model.translators;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.newDomainBase;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static org.junit.Assert.assertThrows;
import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainBase;
import google.registry.model.ofy.CommitLogBucket;
import google.registry.model.ofy.CommitLogCheckpoint;
import google.registry.model.ofy.CommitLogCheckpointRoot;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import google.registry.testing.AppEngineRule;
import org.junit.jupiter.api.Test;
@ -34,7 +37,7 @@ public class VKeyTranslatorFactoryTest {
public VKeyTranslatorFactoryTest() {}
@Test
void testEntityWithVKeyCreate() {
void testEntityWithFlatKey() {
// Creating an objectify key instead of a datastore key as this should get a correctly formatted
// key path.
DomainBase domain = newDomainBase("example.com", "ROID-1", persistActiveContact("contact-1"));
@ -46,13 +49,27 @@ public class VKeyTranslatorFactoryTest {
}
@Test
void testEntityWithoutVKeyCreate() {
CommitLogBucket bucket = new CommitLogBucket.Builder().build();
Key<CommitLogBucket> key = Key.create(bucket);
VKey<CommitLogBucket> vkey = VKeyTranslatorFactory.createVKey(key);
assertThat(vkey.getKind()).isEqualTo(CommitLogBucket.class);
void testKeyWithParent() {
Key<CommitLogCheckpointRoot> parent = Key.create(CommitLogCheckpointRoot.class, "parent");
Key<CommitLogCheckpoint> key = Key.create(parent, CommitLogCheckpoint.class, "foo");
IllegalArgumentException e =
assertThrows(IllegalArgumentException.class, () -> VKeyTranslatorFactory.createVKey(key));
assertThat(e)
.hasMessageThat()
.isEqualTo(
"Cannot auto-convert key Key<?>(CommitLogCheckpointRoot(\"parent\")/"
+ "CommitLogCheckpoint(\"foo\")) of kind CommitLogCheckpoint because it has a "
+ "parent. Add a createVKey(Key) method for it.");
}
@Test
void testEntityWithAncestor() {
Key<HistoryEntry> key =
Key.create(Key.create(DomainBase.class, "ROID-1"), HistoryEntry.class, 101);
VKey<HistoryEntry> vkey = VKeyTranslatorFactory.createVKey(key);
assertThat(vkey.getKind()).isEqualTo(HistoryEntry.class);
assertThat(vkey.getOfyKey()).isEqualTo(key);
assertThat(vkey.maybeGetSqlKey().isPresent()).isFalse();
assertThat(vkey.getSqlKey()).isEqualTo("DomainBase/ROID-1/101");
}
@Test

View file

@ -42,8 +42,6 @@ public class VKeyTest {
assertThat(key.maybeGetSqlKey().isPresent()).isTrue();
assertThat(key.maybeGetOfyKey().isPresent()).isTrue();
Key<TestObject> ofyKey = Key.create(TestObject.create("foo"));
assertThat(VKey.createOfy(TestObject.class, ofyKey).maybeGetOfyKey().get()).isEqualTo(ofyKey);
assertThat(VKey.createSql(TestObject.class, "foo").maybeGetSqlKey().get()).isEqualTo("foo");
}
}