Remove VKeyTranslatorFactory.createVKey(String) (#1312)

* Remove VKeyTranslatorFactory.createVKey(String)

This method serves the same function as VKey.fromWebsafeKey(), and isn't used
anywhere.  Move the test for it into VKeyTest and use it to instead test
fromWebsafeKey() (which didn't previously have a test).
This commit is contained in:
Michael Muller 2021-09-09 12:24:02 -04:00 committed by GitHub
parent 476e85c338
commit 0909a1d6d4
3 changed files with 16 additions and 17 deletions

View file

@ -92,11 +92,6 @@ public class VKeyTranslatorFactory extends AbstractSimpleTranslatorFactory<VKey,
} }
} }
/** Create a VKey from a URL-safe string representation. */
public static VKey<?> createVKey(String urlSafe) {
return createVKey(com.googlecode.objectify.Key.create(urlSafe));
}
@VisibleForTesting @VisibleForTesting
public static void addTestEntityClass(Class<?> clazz) { public static void addTestEntityClass(Class<?> clazz) {
CLASS_REGISTRY.put(com.googlecode.objectify.Key.getKind(clazz), clazz); CLASS_REGISTRY.put(com.googlecode.objectify.Key.getKind(clazz), clazz);

View file

@ -88,18 +88,6 @@ public class VKeyTranslatorFactoryTest {
assertThat(vkey.getSqlKey()).isEqualTo(200L); assertThat(vkey.getSqlKey()).isEqualTo(200L);
} }
@Test
void testUrlSafeKey() {
// 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"));
Key<DomainBase> key = Key.create(domain);
VKey<DomainBase> vkey = (VKey<DomainBase>) VKeyTranslatorFactory.createVKey(key.getString());
assertThat(vkey.getKind()).isEqualTo(DomainBase.class);
assertThat(vkey.getOfyKey()).isEqualTo(key);
assertThat(vkey.getSqlKey()).isEqualTo("ROID-1");
}
@Test @Test
void testExtraEntityClass() { void testExtraEntityClass() {
TestObject testObject = TestObject.create("id", "field"); TestObject testObject = TestObject.create("id", "field");

View file

@ -15,11 +15,14 @@ package google.registry.persistence;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat; import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.DatabaseHelper.newDomainBase;
import static google.registry.testing.DatabaseHelper.persistActiveContact;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Entity;
import google.registry.model.billing.BillingEvent.OneTime; import google.registry.model.billing.BillingEvent.OneTime;
import google.registry.model.domain.DomainBase;
import google.registry.model.registrar.RegistrarContact; import google.registry.model.registrar.RegistrarContact;
import google.registry.testing.AppEngineExtension; import google.registry.testing.AppEngineExtension;
import google.registry.testing.TestObject; import google.registry.testing.TestObject;
@ -114,6 +117,19 @@ class VKeyTest {
.contains("Missing value for last key of type class google.registry.testing.TestObject"); .contains("Missing value for last key of type class google.registry.testing.TestObject");
} }
@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.
DomainBase domain = newDomainBase("example.com", "ROID-1", persistActiveContact("contact-1"));
Key<DomainBase> key = Key.create(domain);
VKey<DomainBase> vkey = VKey.fromWebsafeKey(key.getString());
assertThat(vkey.getKind()).isEqualTo(DomainBase.class);
assertThat(vkey.getOfyKey()).isEqualTo(key);
assertThat(vkey.getSqlKey()).isEqualTo("ROID-1");
}
@Entity @Entity
static class OtherObject {} static class OtherObject {}
} }