mirror of
https://github.com/google/nomulus
synced 2026-09-02 06:07:03 +00:00
Use simple class name of a class in stringify() (#1435)
* Keep CLASS_REGISTRY and CLASS_NAME_REGISTRY up to date * Use simple class name in vkey string
This commit is contained in:
@@ -161,14 +161,13 @@ class VKeyTest {
|
||||
@Test
|
||||
void testStringify_sqlOnlyVKey() throws Exception {
|
||||
assertThat(VKey.createSql(TestObject.class, "foo").stringify())
|
||||
.isEqualTo("kind:google.registry.testing.TestObject@sql:rO0ABXQAA2Zvbw");
|
||||
.isEqualTo("kind:TestObject@sql:rO0ABXQAA2Zvbw");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringify_ofyOnlyVKey() throws Exception {
|
||||
assertThat(VKey.createOfy(TestObject.class, Key.create(TestObject.class, "foo")).stringify())
|
||||
.isEqualTo(
|
||||
"kind:google.registry.testing.TestObject@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M");
|
||||
.isEqualTo("kind:TestObject@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,8 +177,8 @@ class VKeyTest {
|
||||
VKey<DomainBase> vkey = VKey.fromWebsafeKey(key.getString());
|
||||
assertThat(vkey.stringify())
|
||||
.isEqualTo(
|
||||
"kind:google.registry.model.domain.DomainBas"
|
||||
+ "e@sql:rO0ABXQABlJPSUQtMQ"
|
||||
"kind:DomainBase"
|
||||
+ "@sql:rO0ABXQABlJPSUQtMQ"
|
||||
+ "@ofy:agR0ZXN0chYLEgpEb21haW5CYXNlIgZST0lELTEM");
|
||||
}
|
||||
|
||||
@@ -188,7 +187,7 @@ class VKeyTest {
|
||||
assertThat(
|
||||
VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo"))).stringify())
|
||||
.isEqualTo(
|
||||
"kind:google.registry.testing.TestObject@sql:rO0ABXQAA2Zvbw@ofy:agR0ZXN0cjELEg9FbnRpdH"
|
||||
"kind:TestObject@sql:rO0ABXQAA2Zvbw@ofy:agR0ZXN0cjELEg9FbnRpdH"
|
||||
+ "lHcm91cFJvb3QiCWNyb3NzLXRsZAwLEgpUZXN0T2JqZWN0IgNmb28M");
|
||||
}
|
||||
|
||||
@@ -197,22 +196,20 @@ class VKeyTest {
|
||||
assertThat(
|
||||
VKey.create(TestObject.class, "test", Key.create(TestObject.create("foo"))).stringify())
|
||||
.isEqualTo(
|
||||
"kind:google.registry.testing.TestObject@sql:rO0ABXQABHRlc3Q@ofy:agR0ZXN0cjELEg9FbnRpd"
|
||||
"kind:TestObject@sql:rO0ABXQABHRlc3Q@ofy:agR0ZXN0cjELEg9FbnRpd"
|
||||
+ "HlHcm91cFJvb3QiCWNyb3NzLXRsZAwLEgpUZXN0T2JqZWN0IgNmb28M");
|
||||
}
|
||||
|
||||
/** Test create() via different vkey string representations. */
|
||||
@Test
|
||||
void testCreate_stringifedVKey_sqlOnlyVKeyString() throws Exception {
|
||||
assertThat(VKey.create("kind:google.registry.testing.TestObject@sql:rO0ABXQAA2Zvbw"))
|
||||
assertThat(VKey.create("kind:TestObject@sql:rO0ABXQAA2Zvbw"))
|
||||
.isEqualTo(VKey.createSql(TestObject.class, "foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreate_stringifedVKey_ofyOnlyVKeyString() throws Exception {
|
||||
assertThat(
|
||||
VKey.create(
|
||||
"kind:google.registry.testing.TestObject@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M"))
|
||||
assertThat(VKey.create("kind:TestObject@ofy:agR0ZXN0chMLEgpUZXN0T2JqZWN0IgNmb28M"))
|
||||
.isEqualTo(VKey.createOfy(TestObject.class, Key.create(TestObject.class, "foo")));
|
||||
}
|
||||
|
||||
@@ -220,7 +217,7 @@ class VKeyTest {
|
||||
void testCreate_stringifedVKey_asymmetricVKeyString() throws Exception {
|
||||
assertThat(
|
||||
VKey.create(
|
||||
"kind:google.registry.testing.TestObject@sql:rO0ABXQABHRlc3Q@ofy:agR0ZXN0cjELEg9Fb"
|
||||
"kind:TestObject@sql:rO0ABXQABHRlc3Q@ofy:agR0ZXN0cjELEg9Fb"
|
||||
+ "nRpdHlHcm91cFJvb3QiCWNyb3NzLXRsZAwLEgpUZXN0T2JqZWN0IgNmb28M"))
|
||||
.isEqualTo(VKey.create(TestObject.class, "test", Key.create(TestObject.create("foo"))));
|
||||
}
|
||||
@@ -229,7 +226,7 @@ class VKeyTest {
|
||||
void testCreate_stringifedVKey_sqlAndOfyVKeyString() throws Exception {
|
||||
assertThat(
|
||||
VKey.create(
|
||||
"kind:google.registry.testing.TestObject@sql:rO0ABXQAA2Zvbw@ofy:agR0ZXN0cjELEg9Fbn"
|
||||
"kind:TestObject@sql:rO0ABXQAA2Zvbw@ofy:agR0ZXN0cjELEg9Fbn"
|
||||
+ "RpdHlHcm91cFJvb3QiCWNyb3NzLXRsZAwLEgpUZXN0T2JqZWN0IgNmb28M"))
|
||||
.isEqualTo(VKey.create(TestObject.class, "foo", Key.create(TestObject.create("foo"))));
|
||||
}
|
||||
@@ -238,7 +235,7 @@ class VKeyTest {
|
||||
void testCreate_stringifyVkey_fromWebsafeKey() throws Exception {
|
||||
assertThat(
|
||||
VKey.create(
|
||||
"kind:google.registry.model.domain.DomainBase@sql:rO0ABXQABlJPSUQtMQ"
|
||||
"kind:DomainBase@sql:rO0ABXQABlJPSUQtMQ"
|
||||
+ "@ofy:agR0ZXN0chYLEgpEb21haW5CYXNlIgZST0lELTEM"))
|
||||
.isEqualTo(
|
||||
VKey.fromWebsafeKey(
|
||||
@@ -257,11 +254,10 @@ class VKeyTest {
|
||||
void testCreate_invalidStringifiedVKey_failure() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> VKey.create("kind:google.registry.testing.TestObject@sq:l@ofya:bc"));
|
||||
IllegalArgumentException.class, () -> VKey.create("kind:TestObject@sq:l@ofya:bc"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Cannot parse key string: kind:google.registry.testing.TestObject@sq:l@ofya:bc");
|
||||
.contains("Cannot parse key string: kind:TestObject@sq:l@ofya:bc");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user