mirror of
https://github.com/google/nomulus
synced 2026-06-06 23:12:55 +00:00
The only remaining Ofy entity is GaeUserConverter after this PR. (#1838)
Therefore this PR also removed several classes and related tests that support the setup and verification of Ofy entities. In addition, support for creating a VKey from a string is limited to VKey<? extends EppResource> only because it is the only use case (to pass a key to an EPP resource in a web safe way to facilitate resave), and we do not want to keep an extra simple name to class mapping, in addition to what persistence.xml contains. I looked into using PersistenceXmlUtility to obtain the mapping, but the xml file contains classes with the same simple name (namely OneTime from both PollMessage and BillingEvent). It doesn't seem like a worthwhile investment to write more code to deal with that, when the fact is that we only need to consider EppResource.
This commit is contained in:
@@ -112,7 +112,7 @@ public class RegistryJpaReadTest {
|
||||
Read<Object[], String> read =
|
||||
RegistryJpaIO.read(
|
||||
"select d, r.emailAddress from Domain d join Registrar r on"
|
||||
+ " d.currentSponsorClientId = r.registrarId where r.type = :type"
|
||||
+ " d.currentSponsorRegistrarId = r.registrarId where r.type = :type"
|
||||
+ " and d.deletionTime > now()",
|
||||
ImmutableMap.of("type", Registrar.Type.REAL),
|
||||
false,
|
||||
@@ -156,7 +156,7 @@ public class RegistryJpaReadTest {
|
||||
Read<Domain, String> read =
|
||||
RegistryJpaIO.read(
|
||||
"select d from Domain d join Registrar r on"
|
||||
+ " d.currentSponsorClientId = r.registrarId where r.type = :type"
|
||||
+ " d.currentSponsorRegistrarId = r.registrarId where r.type = :type"
|
||||
+ " and d.deletionTime > now()",
|
||||
ImmutableMap.of("type", Registrar.Type.REAL),
|
||||
Domain.class,
|
||||
|
||||
@@ -561,7 +561,7 @@ public class RdePipelineTest {
|
||||
return tm().transact(
|
||||
() ->
|
||||
tm().loadByKey(
|
||||
VKey.createSql(
|
||||
VKey.create(
|
||||
RdeRevision.class,
|
||||
RdeRevisionId.create("soy", now.toLocalDate(), mode)))
|
||||
.getRevision());
|
||||
|
||||
@@ -1353,7 +1353,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
||||
|
||||
private void assertAllocationTokenWasRedeemed(String token) throws Exception {
|
||||
AllocationToken reloadedToken =
|
||||
tm().transact(() -> tm().loadByKey(VKey.createSql(AllocationToken.class, token)));
|
||||
tm().transact(() -> tm().loadByKey(VKey.create(AllocationToken.class, token)));
|
||||
assertThat(reloadedToken.isRedeemed()).isTrue();
|
||||
assertThat(reloadedToken.getRedemptionHistoryId())
|
||||
.hasValue(getHistoryEntries(reloadResourceByForeignKey()).get(0).getHistoryEntryId());
|
||||
@@ -1361,7 +1361,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
||||
|
||||
private void assertAllocationTokenWasNotRedeemed(String token) {
|
||||
AllocationToken reloadedToken =
|
||||
tm().transact(() -> tm().loadByKey(VKey.createSql(AllocationToken.class, token)));
|
||||
tm().transact(() -> tm().loadByKey(VKey.create(AllocationToken.class, token)));
|
||||
assertThat(reloadedToken.isRedeemed()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -382,7 +382,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
|
||||
Domain domainAtRedemptionTime = domain.cloneProjectedAtTime(redemptionEndTime);
|
||||
assertAboutDomains()
|
||||
.that(domainAtRedemptionTime)
|
||||
.hasLastEppUpdateClientId("TheRegistrar")
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar")
|
||||
.and()
|
||||
.hasLastEppUpdateTime(redemptionEndTime);
|
||||
}
|
||||
@@ -930,7 +930,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
|
||||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
assertAboutHistoryEntries()
|
||||
.that(getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE))
|
||||
.hasType(DOMAIN_DELETE)
|
||||
|
||||
@@ -267,7 +267,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
|
||||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId(renewalClientId);
|
||||
.hasLastEppUpdateRegistrarId(renewalClientId);
|
||||
assertAboutHistoryEntries().that(historyEntryDomainRenew).hasPeriodYears(renewalYears);
|
||||
BillingEvent.OneTime renewBillingEvent =
|
||||
new BillingEvent.OneTime.Builder()
|
||||
@@ -332,7 +332,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, Domain>
|
||||
@Test
|
||||
private void assertAllocationTokenWasNotRedeemed(String token) {
|
||||
AllocationToken reloadedToken =
|
||||
tm().transact(() -> tm().loadByKey(VKey.createSql(AllocationToken.class, token)));
|
||||
tm().transact(() -> tm().loadByKey(VKey.create(AllocationToken.class, token)));
|
||||
assertThat(reloadedToken.isRedeemed()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ class DomainRestoreRequestFlowTest extends ResourceFlowTestCase<DomainRestoreReq
|
||||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
assertThat(domain.getGracePeriods()).isEmpty();
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
// The poll message for the delete should now be gone. The only poll message should be the new
|
||||
@@ -255,7 +255,7 @@ class DomainRestoreRequestFlowTest extends ResourceFlowTestCase<DomainRestoreReq
|
||||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
assertThat(domain.getGracePeriods()).isEmpty();
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
// The poll message for the delete should now be gone. The only poll message should be the new
|
||||
|
||||
@@ -138,7 +138,7 @@ class DomainTransferApproveFlowTest
|
||||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
// The domain TransferData should reflect the approved transfer as we expect, with
|
||||
// all the speculative server-approve fields nulled out.
|
||||
assertThat(domain.getTransferData())
|
||||
|
||||
@@ -138,7 +138,7 @@ class DomainTransferCancelFlowTest
|
||||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("NewRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("NewRegistrar");
|
||||
final HistoryEntry historyEntryTransferCancel =
|
||||
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_CANCEL);
|
||||
assertAboutHistoryEntries()
|
||||
|
||||
@@ -108,7 +108,7 @@ class DomainTransferRejectFlowTest
|
||||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
final HistoryEntry historyEntryTransferRejected =
|
||||
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REJECT);
|
||||
assertAboutHistoryEntries()
|
||||
|
||||
@@ -192,7 +192,7 @@ class DomainTransferRequestFlowTest
|
||||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("NewRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("NewRegistrar");
|
||||
Trid expectedTrid =
|
||||
Trid.create(
|
||||
getClientTrid(),
|
||||
@@ -449,7 +449,7 @@ class DomainTransferRequestFlowTest
|
||||
.and()
|
||||
.hasLastEppUpdateTime(implicitTransferTime)
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("NewRegistrar");
|
||||
.hasLastEppUpdateRegistrarId("NewRegistrar");
|
||||
assertThat(loadByKey(domainAfterAutomaticTransfer.getAutorenewBillingEvent()).getEventTime())
|
||||
.isEqualTo(expectedExpirationTime);
|
||||
// And after the expected grace time, the grace period should be gone.
|
||||
|
||||
@@ -56,7 +56,6 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.config.RegistryConfig;
|
||||
import google.registry.flows.EppException;
|
||||
import google.registry.flows.EppException.UnimplementedExtensionException;
|
||||
@@ -90,6 +89,7 @@ import google.registry.flows.domain.DomainFlowUtils.UrgentAttributeNotSupportedE
|
||||
import google.registry.flows.exceptions.OnlyToolCanPassMetadataException;
|
||||
import google.registry.flows.exceptions.ResourceHasClientUpdateProhibitedException;
|
||||
import google.registry.flows.exceptions.ResourceStatusProhibitsOperationException;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.billing.BillingEvent.Reason;
|
||||
import google.registry.model.contact.Contact;
|
||||
@@ -214,7 +214,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
||||
.and()
|
||||
.hasLastEppUpdateTime(clock.nowUtc())
|
||||
.and()
|
||||
.hasLastEppUpdateClientId("TheRegistrar")
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar")
|
||||
.and()
|
||||
.hasNoAutorenewEndTime();
|
||||
assertNoBillingEvents();
|
||||
@@ -1656,7 +1656,9 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
||||
runFlow();
|
||||
assertThat(reloadResourceByForeignKey().getNameservers())
|
||||
.doesNotContain(
|
||||
Key.create(loadByForeignKey(Host.class, "ns1.example.foo", clock.nowUtc()).get()));
|
||||
loadByForeignKey(Host.class, "ns1.example.foo", clock.nowUtc())
|
||||
.map(ImmutableObject::createVKey)
|
||||
.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model;
|
||||
|
||||
import static com.google.common.collect.ImmutableSet.toImmutableSet;
|
||||
import static com.google.common.truth.StreamSubject.streams;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static google.registry.model.EntityClasses.ALL_CLASSES;
|
||||
import static google.registry.util.TypeUtils.hasAnnotation;
|
||||
|
||||
import com.google.common.collect.Ordering;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.EntitySubclass;
|
||||
import java.util.Set;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link EntityClasses}. */
|
||||
class EntityClassesTest {
|
||||
|
||||
// This implements the manual ordering we've been using for the EntityClasses class lists.
|
||||
private static final Ordering<Class<?>> QUALIFIED_CLASS_NAME_ORDERING =
|
||||
Ordering.natural()
|
||||
.onResultOf(
|
||||
clazz -> clazz.getCanonicalName().substring(clazz.getPackage().getName().length()));
|
||||
|
||||
@Test
|
||||
void testEntityClasses_inAlphabeticalOrder() {
|
||||
assertThat(ALL_CLASSES).isInStrictOrder(QUALIFIED_CLASS_NAME_ORDERING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEntityClasses_baseEntitiesHaveUniqueKinds() {
|
||||
assertWithMessage("base entity kinds")
|
||||
.about(streams())
|
||||
.that(ALL_CLASSES.stream().filter(hasAnnotation(Entity.class)).map(Key::getKind))
|
||||
.containsNoDuplicates();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEntityClasses_entitySubclassesHaveKindsMatchingBaseEntities() {
|
||||
Set<String> baseEntityKinds =
|
||||
ALL_CLASSES
|
||||
.stream()
|
||||
.filter(hasAnnotation(Entity.class))
|
||||
.map(Key::getKind)
|
||||
.collect(toImmutableSet());
|
||||
Set<String> entitySubclassKinds =
|
||||
ALL_CLASSES
|
||||
.stream()
|
||||
.filter(hasAnnotation(EntitySubclass.class))
|
||||
.map(Key::getKind)
|
||||
.collect(toImmutableSet());
|
||||
assertWithMessage("base entity kinds")
|
||||
.that(baseEntityKinds)
|
||||
.containsAtLeastElementsIn(entitySubclassKinds);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEntityClasses_eitherBaseEntityOrEntitySubclass() {
|
||||
for (Class<?> clazz : ALL_CLASSES) {
|
||||
boolean isEntityXorEntitySubclass =
|
||||
clazz.isAnnotationPresent(Entity.class) ^ clazz.isAnnotationPresent(EntitySubclass.class);
|
||||
assertWithMessage("class " + clazz.getSimpleName() + " is @Entity or @EntitySubclass")
|
||||
.that(isEntityXorEntitySubclass)
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright 2017 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model;
|
||||
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import google.registry.testing.GoldenFileTestHelper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SchemaVersion}.
|
||||
*
|
||||
* <p>If the test breaks, the instructions below will be printed.
|
||||
*/
|
||||
@DeleteAfterMigration
|
||||
public class SchemaVersionTest {
|
||||
|
||||
@RegisterExtension
|
||||
public final AppEngineExtension appEngine = AppEngineExtension.builder().withCloudSql().build();
|
||||
|
||||
@Test
|
||||
void testGoldenSchemaFile() {
|
||||
GoldenFileTestHelper.assertThat(SchemaVersion.getSchema())
|
||||
.describedAs("Datastore schema")
|
||||
.createdByNomulusCommand("get_schema")
|
||||
.isEqualToGolden(SchemaVersionTest.class, "schema.txt");
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class UpdateAutoTimestampTest {
|
||||
|
||||
private static UpdateAutoTimestampTestObject reload() {
|
||||
return tm().transact(
|
||||
() -> tm().loadByKey(VKey.createSql(UpdateAutoTimestampTestObject.class, 1L)));
|
||||
() -> tm().loadByKey(VKey.create(UpdateAutoTimestampTestObject.class, 1L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
// Copyright 2021 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.common;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import google.registry.model.contact.Contact;
|
||||
import google.registry.model.domain.Domain;
|
||||
import google.registry.model.domain.DomainHistory;
|
||||
import google.registry.model.host.Host;
|
||||
import google.registry.testing.TestObject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link ClassPathManager}. */
|
||||
public class ClassPathManagerTest {
|
||||
@Test
|
||||
void getClass_classInClassRegistry_returnsClass() throws ClassNotFoundException {
|
||||
/*
|
||||
* Class names are used in stringified vkeys, which can be present in task queues. Class name is
|
||||
* required to create a vkey. Changing these names could break task queue entries that are
|
||||
* present during a rollout. If you want to change the names of any of the classses supported in
|
||||
* CLASS_REGISTRY, you'll need to introduce some mechanism to deal with this. One way is to find
|
||||
* the corresponding class name by calling ClassPathManager.getClassName(clazz). The classes
|
||||
* below are all classes supported in CLASS_REGISTRY. This test breaks if someone changes a
|
||||
* classname without preserving the original name.
|
||||
*/
|
||||
assertThat(ClassPathManager.getClass("Host")).isEqualTo(Host.class);
|
||||
assertThat(ClassPathManager.getClass("Contact")).isEqualTo(Contact.class);
|
||||
assertThat(ClassPathManager.getClass("GaeUserIdConverter")).isEqualTo(GaeUserIdConverter.class);
|
||||
assertThat(ClassPathManager.getClass("Domain")).isEqualTo(Domain.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClass_classNotInClassRegistry_throwsException() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> ClassPathManager.getClass("DomainHistory"));
|
||||
assertThat(thrown).hasMessageThat().contains("Class DomainHistory not found in class registry");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClassName_classNotInClassRegistry_throwsException() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> ClassPathManager.getClassName(DomainHistory.class));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Class DomainHistory not found in class name registry");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getClassName() {
|
||||
/*
|
||||
* Class names are used in stringified vkeys, which can be present in task queues. Class name is
|
||||
* required to create a vkey. Changing these names could break task queue entries that are
|
||||
* present during a rollout. If you want to change the names of any of the classses supported in
|
||||
* CLASS_NAME_REGISTRY, you'll need to introduce some mechanism to deal with this.
|
||||
* ClassPathManager.getClassName(clazz) allows you to verify the corresponding name of a class.
|
||||
* The classes below are all classes supported in CLASS_NAME_REGISTRY. This test breaks if
|
||||
* someone changes a classname without preserving the original name.
|
||||
*/
|
||||
assertThat(ClassPathManager.getClassName(Host.class)).isEqualTo("Host");
|
||||
assertThat(ClassPathManager.getClassName(Contact.class)).isEqualTo("Contact");
|
||||
assertThat(ClassPathManager.getClassName(GaeUserIdConverter.class))
|
||||
.isEqualTo("GaeUserIdConverter");
|
||||
assertThat(ClassPathManager.getClassName(Domain.class)).isEqualTo("Domain");
|
||||
}
|
||||
|
||||
@Test
|
||||
void addTestEntityClass_success() {
|
||||
ClassPathManager.addTestEntityClass(TestObject.class);
|
||||
assertThat(ClassPathManager.getClass("TestObject")).isEqualTo(TestObject.class);
|
||||
}
|
||||
}
|
||||
@@ -401,7 +401,7 @@ public class DomainSqlTest {
|
||||
}
|
||||
|
||||
private <T> VKey<T> createKey(Class<T> clazz, String key) {
|
||||
return VKey.createSql(clazz, key);
|
||||
return VKey.create(clazz, key);
|
||||
}
|
||||
|
||||
private void assertEqualDomainExcept(Domain thatDomain, String... excepts) {
|
||||
|
||||
@@ -166,8 +166,8 @@ public class DomainTest {
|
||||
.build();
|
||||
insertInDb(historyEntry, oneTimeBill, recurringBill);
|
||||
recurringBillKey = recurringBill.createVKey();
|
||||
VKey<PollMessage.Autorenew> autorenewPollKey = VKey.createSql(PollMessage.Autorenew.class, 3L);
|
||||
VKey<PollMessage.OneTime> onetimePollKey = VKey.createSql(PollMessage.OneTime.class, 1L);
|
||||
VKey<PollMessage.Autorenew> autorenewPollKey = VKey.create(PollMessage.Autorenew.class, 3L);
|
||||
VKey<PollMessage.OneTime> onetimePollKey = VKey.create(PollMessage.OneTime.class, 1L);
|
||||
// Set up a new persisted domain entity.
|
||||
domain =
|
||||
persistResource(
|
||||
@@ -524,7 +524,7 @@ public class DomainTest {
|
||||
assertThat(beforeAutoRenew.getLastEppUpdateRegistrarId()).isEqualTo("TheRegistrar");
|
||||
|
||||
// If autorenew happens before transfer succeeds(before transfer grace period starts as well),
|
||||
// lastEppUpdateClientId should still be the current sponsor client id
|
||||
// lastEppUpdateRegistrarId should still be the current sponsor client id
|
||||
Domain afterAutoRenew = domain.cloneProjectedAtTime(autorenewDateTime.plusDays(1));
|
||||
assertThat(afterAutoRenew.getLastEppUpdateTime()).isEqualTo(autorenewDateTime);
|
||||
assertThat(afterAutoRenew.getLastEppUpdateRegistrarId()).isEqualTo("NewRegistrar");
|
||||
|
||||
@@ -16,7 +16,6 @@ package google.registry.model.ofy;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ofy.ObjectifyService.initOfy;
|
||||
import static google.registry.testing.DatabaseHelper.newContact;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
|
||||
@@ -27,7 +26,7 @@ import com.googlecode.objectify.ObjectifyFilter;
|
||||
import com.googlecode.objectify.ObjectifyService;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import google.registry.model.contact.Contact;
|
||||
import google.registry.model.common.GaeUserIdConverter;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -81,8 +80,9 @@ class OfyFilterTest {
|
||||
@Test
|
||||
void testKeyCreateAfterFilter() {
|
||||
new OfyFilter().init(null);
|
||||
Contact contact = newContact("contact1234");
|
||||
Key.create(contact);
|
||||
GaeUserIdConverter userIdConverter = new GaeUserIdConverter();
|
||||
userIdConverter.id = 1;
|
||||
Key.create(userIdConverter);
|
||||
}
|
||||
|
||||
@Entity
|
||||
|
||||
@@ -140,6 +140,6 @@ public class PollMessageExternalKeyConverterTest {
|
||||
one.getKind().isAssignableFrom(two.getKind())
|
||||
|| two.getKind().isAssignableFrom(one.getKind()))
|
||||
.isTrue();
|
||||
assertThat(one.getSqlKey()).isEqualTo(two.getSqlKey());
|
||||
assertThat(one.getKey()).isEqualTo(two.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,13 +91,12 @@ public class PollMessageTest extends EntityTestCase {
|
||||
@Test
|
||||
void testCloudSqlSupportForPolymorphicVKey() {
|
||||
insertInDb(oneTime);
|
||||
PollMessage persistedOneTime = loadByKey(VKey.createSql(PollMessage.class, oneTime.getId()));
|
||||
PollMessage persistedOneTime = loadByKey(VKey.create(PollMessage.class, oneTime.getId()));
|
||||
assertThat(persistedOneTime).isInstanceOf(PollMessage.OneTime.class);
|
||||
assertThat(persistedOneTime).isEqualTo(oneTime);
|
||||
|
||||
insertInDb(autoRenew);
|
||||
PollMessage persistedAutoRenew =
|
||||
loadByKey(VKey.createSql(PollMessage.class, autoRenew.getId()));
|
||||
PollMessage persistedAutoRenew = loadByKey(VKey.create(PollMessage.class, autoRenew.getId()));
|
||||
assertThat(persistedAutoRenew).isInstanceOf(PollMessage.Autorenew.class);
|
||||
assertThat(persistedAutoRenew).isEqualTo(autoRenew);
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ public final class Spec11ThreatMatchTest extends EntityTestCase {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
VKey<Host> hostVKey = VKey.createSql(Host.class, "host");
|
||||
VKey<Contact> registrantContactVKey = VKey.createSql(Contact.class, "contact_id");
|
||||
VKey<Host> hostVKey = VKey.create(Host.class, "host");
|
||||
VKey<Contact> registrantContactVKey = VKey.create(Contact.class, "contact_id");
|
||||
String domainRepoId = "4-TLD";
|
||||
createTld("tld");
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ public class TransferDataTest {
|
||||
transferBillingEventKey = OneTime.createVKey(12345L);
|
||||
otherServerApproveBillingEventKey = Cancellation.createVKey(2468L);
|
||||
recurringBillingEventKey = Recurring.createVKey(13579L);
|
||||
autorenewPollMessageKey = VKey.createSql(PollMessage.Autorenew.class, 67890L);
|
||||
otherServerApprovePollMessageKey = VKey.createSql(PollMessage.OneTime.class, 314159L);
|
||||
autorenewPollMessageKey = VKey.create(PollMessage.Autorenew.class, 67890L);
|
||||
otherServerApprovePollMessageKey = VKey.create(PollMessage.OneTime.class, 314159L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -51,9 +51,9 @@ public class StatusValueAdapterTest {
|
||||
new EppResponse.Builder()
|
||||
.setResData(
|
||||
HostInfoData.newBuilder()
|
||||
.setCreationClientId("")
|
||||
.setCreationRegistrarId("")
|
||||
.setCreationTime(START_OF_TIME)
|
||||
.setCurrentSponsorClientId("")
|
||||
.setCurrentSponsorRegistrarId("")
|
||||
.setHostName("")
|
||||
.setInetAddresses(ImmutableSet.of())
|
||||
.setRepoId("")
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.model.translators;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.testing.DatabaseHelper.newDomain;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveContact;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.common.ClassPathManager;
|
||||
import google.registry.model.domain.Domain;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import google.registry.testing.TestObject;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link VKeyTranslatorFactory}. */
|
||||
public class VKeyTranslatorFactoryTest {
|
||||
|
||||
@RegisterExtension
|
||||
public final AppEngineExtension appEngine =
|
||||
AppEngineExtension.builder().withCloudSql().withOfyTestEntities(TestObject.class).build();
|
||||
|
||||
VKeyTranslatorFactoryTest() {}
|
||||
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
ClassPathManager.addTestEntityClass(TestObject.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEntityWithFlatKey() {
|
||||
// Creating an objectify key instead of a datastore key as this should get a correctly formatted
|
||||
// key path.
|
||||
Domain domain = newDomain("example.com", "ROID-1", persistActiveContact("contact-1"));
|
||||
Key<Domain> key = Key.create(domain);
|
||||
VKey<Domain> vkey = VKeyTranslatorFactory.createVKey(key);
|
||||
assertThat(vkey.getKind()).isEqualTo(Domain.class);
|
||||
assertThat(vkey.getOfyKey()).isEqualTo(key);
|
||||
assertThat(vkey.getSqlKey()).isEqualTo("ROID-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExtraEntityClass() {
|
||||
TestObject testObject = TestObject.create("id", "field");
|
||||
Key<TestObject> key = Key.create(testObject);
|
||||
assertThat(VKeyTranslatorFactory.createVKey(key).getSqlKey()).isEqualTo("id");
|
||||
}
|
||||
}
|
||||
@@ -68,14 +68,14 @@ class EntityCallbacksListenerTest {
|
||||
checkAll(updated, 0, 1, 0, 1);
|
||||
|
||||
TestEntity testLoad =
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id")));
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "id")));
|
||||
checkAll(testLoad, 0, 0, 0, 1);
|
||||
|
||||
TestEntity testRemove =
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> {
|
||||
TestEntity removed = jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id"));
|
||||
TestEntity removed = jpaTm().loadByKey(VKey.create(TestEntity.class, "id"));
|
||||
return jpaTm().delete(removed);
|
||||
});
|
||||
checkAll(testRemove, 0, 0, 1, 1);
|
||||
@@ -105,10 +105,10 @@ class EntityCallbacksListenerTest {
|
||||
insertInDb(new TestEntity());
|
||||
|
||||
TestEntity testLoad =
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id")));
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "id")));
|
||||
assertThat(testLoad.entityPreUpdate).isEqualTo(0);
|
||||
|
||||
testLoad = jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "id")));
|
||||
testLoad = jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "id")));
|
||||
|
||||
// Verify that post-load happened but pre-update didn't.
|
||||
assertThat(testLoad.entityPostLoad).isEqualTo(1);
|
||||
|
||||
@@ -14,21 +14,12 @@
|
||||
package google.registry.persistence;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
import static google.registry.testing.DatabaseHelper.newDomain;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveContact;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import google.registry.model.billing.BillingEvent.OneTime;
|
||||
import google.registry.model.common.ClassPathManager;
|
||||
import google.registry.model.domain.Domain;
|
||||
import google.registry.model.host.Host;
|
||||
import google.registry.model.registrar.RegistrarPoc;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import google.registry.testing.TestObject;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
@@ -36,303 +27,80 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
class VKeyTest {
|
||||
|
||||
@RegisterExtension
|
||||
final AppEngineExtension appEngineExtension =
|
||||
AppEngineExtension.builder().withCloudSql().withOfyTestEntities(TestObject.class).build();
|
||||
final JpaIntegrationTestExtension jpa =
|
||||
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
|
||||
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
ClassPathManager.addTestEntityClass(TestObject.class);
|
||||
@Test
|
||||
void testSuccess_createWithLongKey() {
|
||||
VKey<PollMessage> key = VKey.create(PollMessage.class, 5L);
|
||||
assertThat(key.getKey()).isEqualTo(5L);
|
||||
assertThat(key.getKind()).isEqualTo(PollMessage.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOptionalAccessors() {
|
||||
VKey<TestObject> key =
|
||||
VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo")));
|
||||
assertThat(key.maybeGetSqlKey().isPresent()).isTrue();
|
||||
assertThat(key.maybeGetOfyKey().isPresent()).isTrue();
|
||||
assertThat(VKey.createSql(TestObject.class, "foo").maybeGetSqlKey()).hasValue("foo");
|
||||
void testSuccess_createWithStringKey() {
|
||||
VKey<Domain> key = VKey.create(Domain.class, "blah");
|
||||
assertThat(key.getKey()).isEqualTo("blah");
|
||||
assertThat(key.getKind()).isEqualTo(Domain.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateById_failsWhenParentIsNullButShouldntBe() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(IllegalArgumentException.class, () -> VKey.create(OneTime.class, 134L));
|
||||
assertThat(thrown).hasMessageThat().contains("UpdateAutoTimestampEntity");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateByName_failsWhenParentIsNullButShouldntBe() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> VKey.create(RegistrarPoc.class, "fake@example.com"));
|
||||
assertThat(thrown).hasMessageThat().contains("UpdateAutoTimestampEntity");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRestoreOfy() {
|
||||
assertThat(VKey.restoreOfyFrom(null, TestObject.class, 100)).isNull();
|
||||
|
||||
VKey<TestObject> key = VKey.createSql(TestObject.class, "foo");
|
||||
VKey<TestObject> restored = key.restoreOfy(TestObject.class, "bar");
|
||||
assertThat(restored.getOfyKey())
|
||||
.isEqualTo(Key.create(Key.create(TestObject.class, "bar"), TestObject.class, "foo"));
|
||||
assertThat(restored.getSqlKey()).isEqualTo("foo");
|
||||
|
||||
assertThat(VKey.restoreOfyFrom(key).getOfyKey()).isEqualTo(Key.create(TestObject.class, "foo"));
|
||||
|
||||
restored = key.restoreOfy(OtherObject.class, "baz", TestObject.class, "bar");
|
||||
assertThat(restored.getOfyKey())
|
||||
.isEqualTo(
|
||||
Key.create(
|
||||
Key.create(Key.create(OtherObject.class, "baz"), TestObject.class, "bar"),
|
||||
TestObject.class,
|
||||
"foo"));
|
||||
|
||||
// Verify that we can use a key as the first argument.
|
||||
restored = key.restoreOfy(Key.create(TestObject.class, "bar"));
|
||||
assertThat(restored.getOfyKey())
|
||||
.isEqualTo(Key.create(Key.create(TestObject.class, "bar"), TestObject.class, "foo"));
|
||||
|
||||
// Verify that we get an exception when a key is not the first argument.
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> key.restoreOfy(TestObject.class, "foo", Key.create(TestObject.class, "bar")));
|
||||
assertThat(thrown)
|
||||
void testFailure_missingArguments() {
|
||||
assertThat(assertThrows(IllegalArgumentException.class, () -> VKey.create(null, "blah")))
|
||||
.hasMessageThat()
|
||||
.contains("Objectify keys may only be used for the first argument");
|
||||
|
||||
// Verify other exception cases.
|
||||
thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> key.restoreOfy(TestObject.class, TestObject.class));
|
||||
assertThat(thrown)
|
||||
.isEqualTo("kind must not be null");
|
||||
assertThat(assertThrows(IllegalArgumentException.class, () -> VKey.create(Domain.class, null)))
|
||||
.hasMessageThat()
|
||||
.contains("class google.registry.testing.TestObject used as a key value.");
|
||||
.isEqualTo("key must not be null");
|
||||
}
|
||||
|
||||
thrown =
|
||||
assertThrows(IllegalArgumentException.class, () -> key.restoreOfy(TestObject.class, 1.5));
|
||||
assertThat(thrown).hasMessageThat().contains("Key value 1.5 must be a string or long.");
|
||||
@Test
|
||||
void testSuccess_createFromString() {
|
||||
VKey<Domain> key = VKey.createEppVKeyFromString("kind:Domain@sql:rO0ABXQABGJsYWg");
|
||||
assertThat(key.getKey()).isEqualTo("blah");
|
||||
assertThat(key.getKind()).isEqualTo(Domain.class);
|
||||
}
|
||||
|
||||
thrown = assertThrows(IllegalArgumentException.class, () -> key.restoreOfy(TestObject.class));
|
||||
assertThat(thrown)
|
||||
@Test
|
||||
void testFailure_createFromString_missingKind() {
|
||||
assertThat(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> VKey.createEppVKeyFromString("sql:rO0ABXQABGJsYWg")))
|
||||
.hasMessageThat()
|
||||
.contains("Missing value for last key of type class google.registry.testing.TestObject");
|
||||
.isEqualTo("\"kind\" missing from the string: sql:rO0ABXQABGJsYWg");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFromWebsafeKey() {
|
||||
// Creating an objectify key instead of a datastore key as this should get a correctly formatted
|
||||
// key path. We have to one of our actual model object classes for this, TestObject can not be
|
||||
// reconstructed by the VKeyTranslatorFactory.
|
||||
Domain domain = newDomain("example.com", "ROID-1", persistActiveContact("contact-1"));
|
||||
Key<Domain> key = Key.create(domain);
|
||||
VKey<Domain> vkey = VKey.fromWebsafeKey(key.getString());
|
||||
assertThat(vkey.getKind()).isEqualTo(Domain.class);
|
||||
assertThat(vkey.getOfyKey()).isEqualTo(key);
|
||||
assertThat(vkey.getSqlKey()).isEqualTo("ROID-1");
|
||||
}
|
||||
|
||||
/** Test stringify() with vkey created via different ways. */
|
||||
@Test
|
||||
void testStringify_sqlOnlyVKey() {
|
||||
assertThat(VKey.createSql(TestObject.class, "foo").stringify())
|
||||
.isEqualTo("kind:TestObject@sql:rO0ABXQAA2Zvbw");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringify_ofyOnlyVKey() {
|
||||
assertThat(VKey.createOfy(TestObject.class, Key.create(TestObject.class, "foo")).stringify())
|
||||
.isEqualTo("kind:TestObject@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringify_vkeyFromWebsafeKey() {
|
||||
Domain domain = newDomain("example.com", "ROID-1", persistActiveContact("contact-1"));
|
||||
Key<Domain> key = Key.create(domain);
|
||||
VKey<Domain> vkey = VKey.fromWebsafeKey(key.getString());
|
||||
assertThat(vkey.stringify())
|
||||
.isEqualTo(
|
||||
"kind:Domain" + "@sql:rO0ABXQABlJPSUQtMQ" + "@ofy:agR0ZXN0chILEgZEb21haW4iBlJPSUQtMQw");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringify_sqlAndOfyVKey() {
|
||||
void testFailure_createFromString_missingKey() {
|
||||
assertThat(
|
||||
VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo"))).stringify())
|
||||
.isEqualTo("kind:TestObject@sql:rO0ABXQAA2Zvbw@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringify_asymmetricVKey() {
|
||||
assertThat(
|
||||
VKey.create(TestObject.class, "test", Key.create(TestObject.create("foo"))).stringify())
|
||||
.isEqualTo("kind:TestObject@sql:rO0ABXQABHRlc3Q@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M");
|
||||
}
|
||||
|
||||
/** Test create() via different vkey string representations. */
|
||||
@Test
|
||||
void testCreate_stringifedVKey_sqlOnlyVKeyString() {
|
||||
assertThat(VKey.create("kind:TestObject@sql:rO0ABXQAA2Zvbw"))
|
||||
.isEqualTo(VKey.createSql(TestObject.class, "foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifiedVKey_resourceKeyFromTaskQueue() throws Exception {
|
||||
VKey<Host> vkeyFromNewWebsafeKey =
|
||||
VKey.create(
|
||||
"kind:Host@sql:rO0ABXQADzZCQjJGNDc2LUdPT0dMRQ@ofy:ahdzfm"
|
||||
+ "RvbWFpbi1yZWdpc3RyeS1hbHBoYXIhCxIMSG9zdFJlc291cmNlIg82QkIyRjQ3Ni1HT09HTEUM");
|
||||
|
||||
assertThat(vkeyFromNewWebsafeKey.getSqlKey()).isEqualTo("6BB2F476-GOOGLE");
|
||||
assertThat(vkeyFromNewWebsafeKey.getOfyKey().getString())
|
||||
.isEqualTo(
|
||||
"ahdzfmRvbWFpbi1yZWdpc3RyeS1hbHBoYXIhCxIMSG9zdFJlc291cmNlIg82QkIyRjQ3Ni1HT09HTEUM");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifedVKey_ofyOnlyVKeyString() {
|
||||
assertThat(VKey.create("kind:TestObject@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M"))
|
||||
.isEqualTo(VKey.createOfy(TestObject.class, Key.create(TestObject.class, "foo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifedVKey_asymmetricVKeyString() {
|
||||
assertThat(
|
||||
VKey.create(
|
||||
"kind:TestObject@sql:rO0ABXQABHRlc3Q@ofy:agR0ZXN0cjELEg9Fb"
|
||||
+ "nRpdHlHcm91cFJvb3QiCWNyb3NzLXRsZAwLEgpUZXN0T2JqZWN0IgNmb28M"))
|
||||
.isEqualTo(VKey.create(TestObject.class, "test", Key.create(TestObject.create("foo"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifedVKey_sqlAndOfyVKeyString() {
|
||||
assertThat(
|
||||
VKey.create(
|
||||
"kind:TestObject@sql:rO0ABXQAA2Zvbw@ofy:agR0ZXN0cjELEg9Fbn"
|
||||
+ "RpdHlHcm91cFJvb3QiCWNyb3NzLXRsZAwLEgpUZXN0T2JqZWN0IgNmb28M"))
|
||||
.isEqualTo(VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifyVkey_fromWebsafeKey() {
|
||||
assertThat(
|
||||
VKey.create(
|
||||
"kind:Domain@sql:rO0ABXQABlJPSUQtMQ"
|
||||
+ "@ofy:agR0ZXN0chYLEgpEb21haW5CYXNlIgZST0lELTEM"))
|
||||
.isEqualTo(
|
||||
VKey.fromWebsafeKey(
|
||||
Key.create(newDomain("example.com", "ROID-1", persistActiveContact("contact-1")))
|
||||
.getString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifedVKey_websafeKey() {
|
||||
assertThat(VKey.create("agR0ZXN0chkLEgZEb21haW4iDUdBU0RHSDQyMkQtSUQM"))
|
||||
.isEqualTo(VKey.fromWebsafeKey("agR0ZXN0chkLEgZEb21haW4iDUdBU0RHSDQyMkQtSUQM"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_invalidStringifiedVKey_failure() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> VKey.create("kind:TestObject@sq:l@ofya:bc"));
|
||||
assertThat(thrown)
|
||||
assertThrows(
|
||||
IllegalArgumentException.class, () -> VKey.createEppVKeyFromString("kind:Domain")))
|
||||
.hasMessageThat()
|
||||
.contains("Cannot parse key string: kind:TestObject@sq:l@ofya:bc");
|
||||
.isEqualTo("\"sql\" missing from the string: kind:Domain");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_invalidOfyKeyString_failure() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(IllegalArgumentException.class, () -> VKey.create("invalid"));
|
||||
assertThat(thrown).hasMessageThat().contains("Could not parse Reference");
|
||||
}
|
||||
|
||||
/** Test stringify() then create() flow. */
|
||||
@Test
|
||||
void testStringifyThenCreate_sqlOnlyVKey_testObject_stringKey_success() {
|
||||
VKey<TestObject> vkey = VKey.createSql(TestObject.class, "foo");
|
||||
VKey<TestObject> newVkey = VKey.create(vkey.stringify());
|
||||
assertThat(newVkey).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_sqlOnlyVKey_testObject_longKey_success() {
|
||||
VKey<TestObject> vkey = VKey.createSql(TestObject.class, (long) 12345);
|
||||
VKey<TestObject> newVkey = VKey.create(vkey.stringify());
|
||||
assertThat(newVkey).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_createFromExistingOfyKey_success() {
|
||||
String keyString =
|
||||
Key.create(newDomain("example.com", "ROID-1", persistActiveContact("contact-1")))
|
||||
.getString();
|
||||
assertThat(VKey.fromWebsafeKey(keyString)).isEqualTo(VKey.create(keyString));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_ofyOnlyVKey_testObject_success() {
|
||||
VKey<TestObject> vkey =
|
||||
VKey.createOfy(TestObject.class, Key.create(TestObject.class, "tmpKey"));
|
||||
assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_ofyOnlyVKey_testObject_websafeString_success() {
|
||||
VKey<TestObject> vkey = VKey.fromWebsafeKey(Key.create(TestObject.create("foo")).getString());
|
||||
assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_sqlAndOfyVKey_success() {
|
||||
VKey<TestObject> vkey =
|
||||
VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo")));
|
||||
assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_asymmetricVKey_success() {
|
||||
VKey<TestObject> vkey =
|
||||
VKey.create(TestObject.class, "sqlKey", Key.create(TestObject.create("foo")));
|
||||
assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringifyThenCreate_symmetricVKey_success() {
|
||||
VKey<TestObject> vkey = TestObject.create("foo").key();
|
||||
assertThat(VKey.create(vkey.stringify())).isEqualTo(vkey);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString_sqlOnlyVKey() {
|
||||
assertThat(VKey.createSql(TestObject.class, "testId").toString())
|
||||
.isEqualTo("VKey<TestObject>(sql:testId)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString_ofyOnlyVKey_withName() {
|
||||
void testFailure_createFromString_wrongKind() {
|
||||
assertThat(
|
||||
VKey.createOfy(TestObject.class, Key.create(TestObject.class, "testName")).toString())
|
||||
.isEqualTo("VKey<TestObject>(ofy:testName)");
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> VKey.createEppVKeyFromString("kind:Registry@sql:rO0ABXQABGJsYWg")))
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Registry is not an EppResource");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString_ofyOnlyVKey_withId() {
|
||||
assertThat(VKey.createOfy(TestObject.class, Key.create(TestObject.class, 12345)).toString())
|
||||
.isEqualTo("VKey<TestObject>(ofy:12345)");
|
||||
void testSuccess_stringify() {
|
||||
VKey<Domain> key = VKey.create(Domain.class, "blah");
|
||||
String keyString = key.stringify();
|
||||
assertThat(keyString).isEqualTo("kind:Domain@sql:rO0ABXQABGJsYWg");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString_sqlAndOfyVKey() {
|
||||
assertThat(
|
||||
VKey.create(TestObject.class, "foo", Key.create(TestObject.create("ofy"))).toString())
|
||||
.isEqualTo("VKey<TestObject>(sql:foo,ofy:ofy)");
|
||||
void testSuccess_toString() {
|
||||
VKey<Domain> key = VKey.create(Domain.class, "blah");
|
||||
String keyString = key.toString();
|
||||
assertThat(keyString).isEqualTo("VKey<Domain>(sql:blah)");
|
||||
}
|
||||
|
||||
@Entity
|
||||
static class OtherObject {}
|
||||
}
|
||||
|
||||
@@ -66,8 +66,7 @@ public class InetAddressSetConverterTest {
|
||||
insertInDb(testEntity);
|
||||
InetAddressSetTestEntity persisted =
|
||||
jpaTm()
|
||||
.transact(
|
||||
() -> jpaTm().loadByKey(VKey.createSql(InetAddressSetTestEntity.class, "id")));
|
||||
.transact(() -> jpaTm().loadByKey(VKey.create(InetAddressSetTestEntity.class, "id")));
|
||||
assertThat(persisted.addresses).isEqualTo(inetAddresses);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,8 +56,7 @@ public class LocalDateConverterTest {
|
||||
LocalDateConverterTestEntity entity = new LocalDateConverterTestEntity(date);
|
||||
insertInDb(entity);
|
||||
return jpaTm()
|
||||
.transact(
|
||||
() -> jpaTm().loadByKey(VKey.createSql(LocalDateConverterTestEntity.class, "id")));
|
||||
.transact(() -> jpaTm().loadByKey(VKey.create(LocalDateConverterTestEntity.class, "id")));
|
||||
}
|
||||
|
||||
/** Override entity name to avoid the nested class reference. */
|
||||
|
||||
@@ -46,9 +46,9 @@ public class VKeyConverterTest {
|
||||
@Test
|
||||
void testRoundTrip() {
|
||||
TestStringEntity stringEntity = new TestStringEntity("TheRealSpartacus");
|
||||
VKey<TestStringEntity> stringKey = VKey.createSql(TestStringEntity.class, "TheRealSpartacus");
|
||||
VKey<TestStringEntity> stringKey = VKey.create(TestStringEntity.class, "TheRealSpartacus");
|
||||
TestLongEntity longEntity = new TestLongEntity(300L);
|
||||
VKey<TestLongEntity> longKey = VKey.createSql(TestLongEntity.class, 300L);
|
||||
VKey<TestLongEntity> longKey = VKey.create(TestLongEntity.class, 300L);
|
||||
TestEntity original = new TestEntity(1984L, stringKey, longKey);
|
||||
insertInDb(stringEntity, longEntity, original);
|
||||
|
||||
|
||||
@@ -60,11 +60,11 @@ class JpaTransactionManagerImplTest {
|
||||
|
||||
private final FakeClock fakeClock = new FakeClock();
|
||||
private final TestEntity theEntity = new TestEntity("theEntity", "foo");
|
||||
private final VKey<TestEntity> theEntityKey = VKey.createSql(TestEntity.class, "theEntity");
|
||||
private final VKey<TestEntity> theEntityKey = VKey.create(TestEntity.class, "theEntity");
|
||||
private final TestCompoundIdEntity compoundIdEntity =
|
||||
new TestCompoundIdEntity("compoundIdEntity", 10, "foo");
|
||||
private final VKey<TestCompoundIdEntity> compoundIdEntityKey =
|
||||
VKey.createSql(TestCompoundIdEntity.class, new CompoundId("compoundIdEntity", 10));
|
||||
VKey.create(TestCompoundIdEntity.class, new CompoundId("compoundIdEntity", 10));
|
||||
private final ImmutableList<TestEntity> moreEntities =
|
||||
ImmutableList.of(
|
||||
new TestEntity("entity1", "foo"),
|
||||
@@ -228,8 +228,7 @@ class JpaTransactionManagerImplTest {
|
||||
jpaTm().transact(() -> jpaTm().insert(entity));
|
||||
assertThat(existsInDb(entity)).isTrue();
|
||||
assertThat(
|
||||
loadByKey(
|
||||
VKey.createSql(TestNamedCompoundIdEntity.class, new NamedCompoundId("foo", 1))))
|
||||
loadByKey(VKey.create(TestNamedCompoundIdEntity.class, new NamedCompoundId("foo", 1))))
|
||||
.isEqualTo(entity);
|
||||
}
|
||||
|
||||
@@ -289,7 +288,7 @@ class JpaTransactionManagerImplTest {
|
||||
void update_succeeds() {
|
||||
insertInDb(theEntity);
|
||||
TestEntity persisted =
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.createSql(TestEntity.class, "theEntity")));
|
||||
jpaTm().transact(() -> jpaTm().loadByKey(VKey.create(TestEntity.class, "theEntity")));
|
||||
assertThat(persisted.data).isEqualTo("foo");
|
||||
theEntity.data = "bar";
|
||||
jpaTm().transact(() -> jpaTm().update(theEntity));
|
||||
@@ -415,7 +414,7 @@ class JpaTransactionManagerImplTest {
|
||||
jpaTm()
|
||||
.loadByKeysIfPresent(
|
||||
ImmutableList.of(
|
||||
theEntityKey, VKey.createSql(TestEntity.class, "does-not-exist")));
|
||||
theEntityKey, VKey.create(TestEntity.class, "does-not-exist")));
|
||||
|
||||
assertThat(results).containsExactly(theEntityKey, theEntity);
|
||||
assertDetachedFromEntityManager(results.get(theEntityKey));
|
||||
|
||||
@@ -23,18 +23,17 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.truth.Truth8;
|
||||
import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.testing.AppEngineExtension;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions.JpaUnitTestExtension;
|
||||
import google.registry.testing.FakeClock;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -53,13 +52,11 @@ public class TransactionManagerTest {
|
||||
new TestEntity("entity3", "qux"));
|
||||
|
||||
@RegisterExtension
|
||||
public final AppEngineExtension appEngine =
|
||||
AppEngineExtension.builder()
|
||||
public final JpaUnitTestExtension jpa =
|
||||
new JpaTestExtensions.Builder()
|
||||
.withClock(fakeClock)
|
||||
.withCloudSql()
|
||||
.withOfyTestEntities(TestEntity.class)
|
||||
.withJpaUnitTestEntities(TestEntity.class, TestEntityBase.class)
|
||||
.build();
|
||||
.withEntityClass(TestEntity.class, TestEntityBase.class)
|
||||
.buildUnitTestExtension();
|
||||
|
||||
TransactionManagerTest() {}
|
||||
|
||||
@@ -116,7 +113,7 @@ public class TransactionManagerTest {
|
||||
assertEntityNotExist(theEntity);
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
assertEntityExists(theEntity);
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.key()))).isEqualTo(theEntity);
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.createVKey()))).isEqualTo(theEntity);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -131,17 +128,17 @@ public class TransactionManagerTest {
|
||||
assertEntityNotExist(theEntity);
|
||||
tm().transact(() -> tm().put(theEntity));
|
||||
assertEntityExists(theEntity);
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.key()))).isEqualTo(theEntity);
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.createVKey()))).isEqualTo(theEntity);
|
||||
}
|
||||
|
||||
@Test
|
||||
void saveNewOrUpdate_updatesExistingEntity() {
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
TestEntity persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
|
||||
TestEntity persisted = tm().transact(() -> tm().loadByKey(theEntity.createVKey()));
|
||||
assertThat(persisted.data).isEqualTo("foo");
|
||||
theEntity.data = "bar";
|
||||
tm().transact(() -> tm().put(theEntity));
|
||||
persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
|
||||
persisted = tm().transact(() -> tm().loadByKey(theEntity.createVKey()));
|
||||
assertThat(persisted.data).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@@ -156,14 +153,11 @@ public class TransactionManagerTest {
|
||||
void update_succeeds() {
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
TestEntity persisted =
|
||||
tm().transact(
|
||||
() ->
|
||||
tm().loadByKey(
|
||||
VKey.create(TestEntity.class, theEntity.name, Key.create(theEntity))));
|
||||
tm().transact(() -> tm().loadByKey(VKey.create(TestEntity.class, theEntity.name)));
|
||||
assertThat(persisted.data).isEqualTo("foo");
|
||||
theEntity.data = "bar";
|
||||
tm().transact(() -> tm().update(theEntity));
|
||||
persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
|
||||
persisted = tm().transact(() -> tm().loadByKey(theEntity.createVKey()));
|
||||
assertThat(persisted.data).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@@ -171,7 +165,7 @@ public class TransactionManagerTest {
|
||||
void load_succeeds() {
|
||||
assertEntityNotExist(theEntity);
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
TestEntity persisted = tm().transact(() -> tm().loadByKey(theEntity.key()));
|
||||
TestEntity persisted = tm().transact(() -> tm().loadByKey(theEntity.createVKey()));
|
||||
assertThat(persisted.name).isEqualTo("theEntity");
|
||||
assertThat(persisted.data).isEqualTo("foo");
|
||||
}
|
||||
@@ -180,14 +174,16 @@ public class TransactionManagerTest {
|
||||
void load_throwsOnMissingElement() {
|
||||
assertEntityNotExist(theEntity);
|
||||
assertThrows(
|
||||
NoSuchElementException.class, () -> tm().transact(() -> tm().loadByKey(theEntity.key())));
|
||||
NoSuchElementException.class,
|
||||
() -> tm().transact(() -> tm().loadByKey(theEntity.createVKey())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void maybeLoad_succeeds() {
|
||||
assertEntityNotExist(theEntity);
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
TestEntity persisted = tm().transact(() -> tm().loadByKeyIfPresent(theEntity.key()).get());
|
||||
TestEntity persisted =
|
||||
tm().transact(() -> tm().loadByKeyIfPresent(theEntity.createVKey()).get());
|
||||
assertThat(persisted.name).isEqualTo("theEntity");
|
||||
assertThat(persisted.data).isEqualTo("foo");
|
||||
}
|
||||
@@ -195,21 +191,22 @@ public class TransactionManagerTest {
|
||||
@Test
|
||||
void maybeLoad_nonExistentObject() {
|
||||
assertEntityNotExist(theEntity);
|
||||
assertThat(tm().transact(() -> tm().loadByKeyIfPresent(theEntity.key())).isPresent()).isFalse();
|
||||
assertThat(tm().transact(() -> tm().loadByKeyIfPresent(theEntity.createVKey())).isPresent())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_succeeds() {
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
assertEntityExists(theEntity);
|
||||
tm().transact(() -> tm().delete(theEntity.key()));
|
||||
tm().transact(() -> tm().delete(theEntity.createVKey()));
|
||||
assertEntityNotExist(theEntity);
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_doNothingWhenEntityNotExist() {
|
||||
assertEntityNotExist(theEntity);
|
||||
tm().transact(() -> tm().delete(theEntity.key()));
|
||||
tm().transact(() -> tm().delete(theEntity.createVKey()));
|
||||
assertEntityNotExist(theEntity);
|
||||
}
|
||||
|
||||
@@ -218,7 +215,7 @@ public class TransactionManagerTest {
|
||||
assertAllEntitiesNotExist(moreEntities);
|
||||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
Set<VKey<TestEntity>> keys =
|
||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableSet());
|
||||
moreEntities.stream().map(TestEntity::createVKey).collect(toImmutableSet());
|
||||
assertAllEntitiesExist(moreEntities);
|
||||
tm().transact(() -> tm().delete(keys));
|
||||
assertAllEntitiesNotExist(moreEntities);
|
||||
@@ -229,7 +226,7 @@ public class TransactionManagerTest {
|
||||
assertAllEntitiesNotExist(moreEntities);
|
||||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
List<VKey<TestEntity>> keys =
|
||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
||||
moreEntities.stream().map(TestEntity::createVKey).collect(toImmutableList());
|
||||
assertAllEntitiesExist(moreEntities);
|
||||
tm().transact(() -> tm().delete(keys.get(0)));
|
||||
assertEntityNotExist(moreEntities.get(0));
|
||||
@@ -250,9 +247,9 @@ public class TransactionManagerTest {
|
||||
assertAllEntitiesNotExist(moreEntities);
|
||||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
List<VKey<TestEntity>> keys =
|
||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
||||
moreEntities.stream().map(TestEntity::createVKey).collect(toImmutableList());
|
||||
assertThat(tm().transact(() -> tm().loadByKeys(keys)))
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::key));
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::createVKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -260,11 +257,11 @@ public class TransactionManagerTest {
|
||||
assertAllEntitiesNotExist(moreEntities);
|
||||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
ImmutableList<VKey<TestEntity>> keys =
|
||||
moreEntities.stream().map(TestEntity::key).collect(toImmutableList());
|
||||
moreEntities.stream().map(TestEntity::createVKey).collect(toImmutableList());
|
||||
ImmutableList<VKey<TestEntity>> doubleKeys =
|
||||
Stream.concat(keys.stream(), keys.stream()).collect(toImmutableList());
|
||||
assertThat(tm().transact(() -> tm().loadByKeys(doubleKeys)))
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::key));
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::createVKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,7 +270,7 @@ public class TransactionManagerTest {
|
||||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
List<VKey<TestEntity>> keys =
|
||||
Stream.concat(moreEntities.stream(), Stream.of(new TestEntity("dark", "matter")))
|
||||
.map(TestEntity::key)
|
||||
.map(TestEntity::createVKey)
|
||||
.collect(toImmutableList());
|
||||
assertThat(
|
||||
assertThrows(
|
||||
@@ -288,10 +285,10 @@ public class TransactionManagerTest {
|
||||
tm().transact(() -> tm().insertAll(moreEntities));
|
||||
List<VKey<TestEntity>> keys =
|
||||
Stream.concat(moreEntities.stream(), Stream.of(new TestEntity("dark", "matter")))
|
||||
.map(TestEntity::key)
|
||||
.map(TestEntity::createVKey)
|
||||
.collect(toImmutableList());
|
||||
assertThat(tm().transact(() -> tm().loadByKeysIfPresent(keys)))
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::key));
|
||||
.isEqualTo(Maps.uniqueIndex(moreEntities, TestEntity::createVKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -322,8 +319,8 @@ public class TransactionManagerTest {
|
||||
tm().transact(
|
||||
() ->
|
||||
tm().loadByEntitiesIfPresent(moreEntities).stream()
|
||||
.map(TestEntity::key)
|
||||
.map(VKey::getSqlKey)
|
||||
.map(TestEntity::createVKey)
|
||||
.map(VKey::getKey)
|
||||
.collect(toImmutableList())))
|
||||
.containsExactly("entity2", "entity3");
|
||||
}
|
||||
@@ -355,10 +352,10 @@ public class TransactionManagerTest {
|
||||
tm().transact(() -> tm().insert(theEntity));
|
||||
tm().transact(
|
||||
() -> {
|
||||
TestEntity e = tm().loadByKey(theEntity.key());
|
||||
TestEntity e = tm().loadByKey(theEntity.createVKey());
|
||||
e.data = "some other data!";
|
||||
});
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.key())).data).isEqualTo("foo");
|
||||
assertThat(tm().transact(() -> tm().loadByKey(theEntity.createVKey())).data).isEqualTo("foo");
|
||||
}
|
||||
|
||||
private static void assertEntityExists(TestEntity entity) {
|
||||
@@ -383,7 +380,7 @@ public class TransactionManagerTest {
|
||||
@MappedSuperclass
|
||||
@Embeddable
|
||||
private static class TestEntityBase extends ImmutableObject {
|
||||
@Id @javax.persistence.Id protected String name;
|
||||
@Id protected String name;
|
||||
|
||||
TestEntityBase(String name) {
|
||||
this.name = name;
|
||||
@@ -392,8 +389,7 @@ public class TransactionManagerTest {
|
||||
TestEntityBase() {}
|
||||
}
|
||||
|
||||
@Entity(name = "TxnMgrTestEntity")
|
||||
@javax.persistence.Entity(name = "TestEntity")
|
||||
@Entity(name = "TestEntity")
|
||||
private static class TestEntity extends TestEntityBase {
|
||||
|
||||
private String data;
|
||||
@@ -405,8 +401,9 @@ public class TransactionManagerTest {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public VKey<TestEntity> key() {
|
||||
return VKey.create(TestEntity.class, name, Key.create(this));
|
||||
@Override
|
||||
public VKey<TestEntity> createVKey() {
|
||||
return VKey.create(TestEntity.class, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class RegistrarDaoTest {
|
||||
JpaIntegrationWithCoverageExtension jpa =
|
||||
new JpaTestExtensions.Builder().withClock(fakeClock).buildIntegrationWithCoverageExtension();
|
||||
|
||||
private final VKey<Registrar> registrarKey = VKey.createSql(Registrar.class, "registrarId");
|
||||
private final VKey<Registrar> registrarKey = VKey.create(Registrar.class, "registrarId");
|
||||
|
||||
private Registrar testRegistrar;
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ abstract class AbstractEppResourceSubject<
|
||||
return andChainer();
|
||||
}
|
||||
|
||||
public And<S> hasLastEppUpdateClientId(String registrarId) {
|
||||
public And<S> hasLastEppUpdateRegistrarId(String registrarId) {
|
||||
return hasValue(
|
||||
registrarId, actual.getLastEppUpdateRegistrarId(), "getLastEppUpdateRegistrarId()");
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@ import com.googlecode.objectify.Key;
|
||||
import com.googlecode.objectify.annotation.Entity;
|
||||
import com.googlecode.objectify.annotation.Id;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import google.registry.model.annotations.VirtualEntity;
|
||||
import google.registry.persistence.VKey;
|
||||
|
||||
/** A test model object that can be persisted in any entity group. */
|
||||
@DeleteAfterMigration
|
||||
@Entity
|
||||
@javax.persistence.Entity
|
||||
public class TestObject extends ImmutableObject {
|
||||
|
||||
@Id @javax.persistence.Id String id;
|
||||
@@ -39,11 +40,7 @@ public class TestObject extends ImmutableObject {
|
||||
}
|
||||
|
||||
public VKey<TestObject> key() {
|
||||
return VKey.create(TestObject.class, id, Key.create(this));
|
||||
}
|
||||
|
||||
public static VKey<TestObject> createVKey(Key<TestObject> key) {
|
||||
return VKey.create(TestObject.class, key.getName(), key);
|
||||
return VKey.create(TestObject.class, id);
|
||||
}
|
||||
|
||||
public static TestObject create(String id) {
|
||||
|
||||
@@ -48,7 +48,7 @@ class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
|
||||
persistActiveDomain("example.tld");
|
||||
runCommand("example.tld", "--expand");
|
||||
assertInStdout("domainName=example.tld");
|
||||
assertInStdout("sqlKey=3-ROID");
|
||||
assertInStdout("key=3-ROID");
|
||||
assertInStdout("Websafe key: " + "kind:Domain" + "@sql:rO0ABXQABTItVExE");
|
||||
assertNotInStdout("LiveRef");
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
|
||||
persistActiveDomain("xn--aualito-txac.xn--q9jyb4c");
|
||||
runCommand("çauçalito.みんな", "--expand");
|
||||
assertInStdout("domainName=xn--aualito-txac.xn--q9jyb4c");
|
||||
assertInStdout("sqlKey=4-ROID");
|
||||
assertInStdout("key=4-ROID");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -101,7 +101,7 @@ public class MutatingCommandTest {
|
||||
+ "lastEppUpdateTime: null -> 2014-09-09T09:09:09.000Z\n"
|
||||
+ "\n"
|
||||
+ "Update Host@3-ROID\n"
|
||||
+ "currentSponsorClientId: TheRegistrar -> Registrar2\n"
|
||||
+ "currentSponsorRegistrarId: TheRegistrar -> Registrar2\n"
|
||||
+ "\n"
|
||||
+ "Update Registrar@Registrar1\n"
|
||||
+ "poNumber: null -> 23\n"
|
||||
@@ -246,7 +246,7 @@ public class MutatingCommandTest {
|
||||
+ "\n"
|
||||
+ "\n"
|
||||
+ "Update Host@3-ROID\n"
|
||||
+ "currentSponsorClientId: TheRegistrar -> Registrar2\n"
|
||||
+ "currentSponsorRegistrarId: TheRegistrar -> Registrar2\n"
|
||||
+ "\n"
|
||||
+ "Delete Registrar@Registrar1\n"
|
||||
+ registrar1
|
||||
@@ -289,7 +289,7 @@ public class MutatingCommandTest {
|
||||
+ "\n"
|
||||
+ "\n"
|
||||
+ "Update Host@3-ROID\n"
|
||||
+ "currentSponsorClientId: TheRegistrar -> Registrar2\n"
|
||||
+ "currentSponsorRegistrarId: TheRegistrar -> Registrar2\n"
|
||||
+ "\n"
|
||||
+ "Delete Registrar@Registrar1\n"
|
||||
+ registrar1
|
||||
|
||||
@@ -145,7 +145,7 @@ public class CreateCancellationsForOneTimesCommandTest
|
||||
private void assertBillingEventCancelled(long oneTimeId) {
|
||||
assertThat(
|
||||
DatabaseHelper.loadAllOf(Cancellation.class).stream()
|
||||
.anyMatch(c -> c.getEventKey().equals(VKey.createSql(OneTime.class, oneTimeId))))
|
||||
.anyMatch(c -> c.getEventKey().equals(VKey.create(OneTime.class, oneTimeId))))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
class google.registry.model.common.GaeUserIdConverter {
|
||||
@Id long id;
|
||||
com.google.appengine.api.users.User user;
|
||||
}
|
||||
class google.registry.model.contact.Contact {
|
||||
@Id java.lang.String repoId;
|
||||
java.lang.String contactId;
|
||||
java.lang.String creationClientId;
|
||||
java.lang.String currentSponsorClientId;
|
||||
java.lang.String email;
|
||||
java.lang.String lastEppUpdateClientId;
|
||||
java.lang.String searchName;
|
||||
org.joda.time.DateTime deletionTime;
|
||||
org.joda.time.DateTime lastEppUpdateTime;
|
||||
org.joda.time.DateTime lastTransferTime;
|
||||
}
|
||||
class google.registry.model.domain.Domain {
|
||||
@Id java.lang.String repoId;
|
||||
google.registry.persistence.VKey<google.registry.model.contact.Contact> adminContact;
|
||||
google.registry.persistence.VKey<google.registry.model.contact.Contact> billingContact;
|
||||
google.registry.persistence.VKey<google.registry.model.contact.Contact> registrantContact;
|
||||
google.registry.persistence.VKey<google.registry.model.contact.Contact> techContact;
|
||||
google.registry.persistence.VKey<google.registry.model.poll.PollMessage$Autorenew> autorenewPollMessage;
|
||||
google.registry.persistence.VKey<google.registry.model.poll.PollMessage$OneTime> deletePollMessage;
|
||||
java.lang.String creationClientId;
|
||||
java.lang.String currentSponsorClientId;
|
||||
java.lang.String domainName;
|
||||
java.lang.String idnTableName;
|
||||
java.lang.String lastEppUpdateClientId;
|
||||
java.lang.String smdId;
|
||||
java.lang.String tld;
|
||||
java.util.Set<google.registry.persistence.VKey<google.registry.model.host.Host>> nsHosts;
|
||||
java.util.Set<java.lang.String> subordinateHosts;
|
||||
org.joda.time.DateTime autorenewEndTime;
|
||||
org.joda.time.DateTime deletionTime;
|
||||
org.joda.time.DateTime lastEppUpdateTime;
|
||||
org.joda.time.DateTime lastTransferTime;
|
||||
org.joda.time.DateTime registrationExpirationTime;
|
||||
}
|
||||
class google.registry.model.host.Host {
|
||||
@Id java.lang.String repoId;
|
||||
google.registry.persistence.VKey<google.registry.model.domain.Domain> superordinateDomain;
|
||||
java.lang.String creationClientId;
|
||||
java.lang.String currentSponsorClientId;
|
||||
java.lang.String hostName;
|
||||
java.lang.String lastEppUpdateClientId;
|
||||
java.util.Set<java.net.InetAddress> inetAddresses;
|
||||
org.joda.time.DateTime deletionTime;
|
||||
org.joda.time.DateTime lastEppUpdateTime;
|
||||
org.joda.time.DateTime lastSuperordinateChange;
|
||||
org.joda.time.DateTime lastTransferTime;
|
||||
}
|
||||
Reference in New Issue
Block a user