Replace loadByUniqueId() with methods that don't overload unique id

It is replaced by loadByForeignKey(), which does the same thing that
loadByUniqueId() did for contacts, hosts, and domains, and also
loadDomainApplication(), which loads domain application by ROID. This eliminates
the ugly mode-switching of attemping to load by other foreign key or ROID.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=133980156
This commit is contained in:
mcilwain 2016-09-22 11:45:58 -07:00 committed by Ben McIlwain
parent 025a4ae012
commit 21a98b899c
57 changed files with 367 additions and 340 deletions

View file

@ -76,11 +76,11 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
assertTransactionalFlow(true);
runFlowAssertResponse(readFile("host_create_response.xml"));
// Check that the host was created and persisted with a history entry.
assertAboutHosts().that(reloadResourceByUniqueId())
assertAboutHosts().that(reloadResourceByForeignKey())
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.HOST_CREATE);
assertNoBillingEvents();
assertEppResourceIndexEntityFor(reloadResourceByUniqueId());
assertEppResourceIndexEntityFor(reloadResourceByForeignKey());
}
private void doSuccessfulInternalTest(String tld) throws Exception {
@ -104,10 +104,10 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
@Test
public void testSuccess_internalNeverExisted() throws Exception {
doSuccessfulInternalTest("tld");
assertThat(ofy().load().key(reloadResourceByUniqueId().getSuperordinateDomain())
assertThat(ofy().load().key(reloadResourceByForeignKey().getSuperordinateDomain())
.now().getFullyQualifiedDomainName())
.isEqualTo("example.tld");
assertThat(ofy().load().key(reloadResourceByUniqueId().getSuperordinateDomain())
assertThat(ofy().load().key(reloadResourceByForeignKey().getSuperordinateDomain())
.now().getSubordinateHosts()).containsExactly("ns1.example.tld");
assertDnsTasksEnqueued("ns1.example.tld");
}
@ -123,10 +123,10 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
public void testSuccess_internalExistedButWasDeleted() throws Exception {
persistDeletedHost(getUniqueIdFromCommand(), clock.nowUtc());
doSuccessfulInternalTest("tld");
assertThat(ofy().load().key(reloadResourceByUniqueId().getSuperordinateDomain())
assertThat(ofy().load().key(reloadResourceByForeignKey().getSuperordinateDomain())
.now().getFullyQualifiedDomainName())
.isEqualTo("example.tld");
assertThat(ofy().load().key(reloadResourceByUniqueId().getSuperordinateDomain())
assertThat(ofy().load().key(reloadResourceByForeignKey().getSuperordinateDomain())
.now().getSubordinateHosts()).containsExactly("ns1.example.tld");
assertDnsTasksEnqueued("ns1.example.tld");
}

View file

@ -67,7 +67,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
clock.advanceOneMilli();
assertTransactionalFlow(true);
runFlowAssertResponse(readFile("host_delete_response.xml"));
HostResource deletedHost = reloadResourceByUniqueId();
HostResource deletedHost = reloadResourceByForeignKey();
assertAboutHosts().that(deletedHost).hasStatusValue(StatusValue.PENDING_DELETE);
assertAsyncDeletionTaskEnqueued(deletedHost, "TheRegistrar", false);
assertAboutHosts().that(deletedHost)
@ -127,7 +127,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
clock.advanceOneMilli();
runFlowAssertResponse(
CommitMode.LIVE, UserPrivileges.SUPERUSER, readFile("host_delete_response.xml"));
HostResource deletedHost = reloadResourceByUniqueId();
HostResource deletedHost = reloadResourceByForeignKey();
assertAboutHosts().that(deletedHost).hasStatusValue(StatusValue.PENDING_DELETE);
assertAsyncDeletionTaskEnqueued(deletedHost, "NewRegistrar", true);
assertAboutHosts().that(deletedHost)

View file

@ -15,7 +15,7 @@
package google.registry.flows.host;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.request.Actions.getPathForAction;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld;
@ -106,10 +106,10 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
runFlowAssertResponse(readFile("host_update_response.xml"));
// The example xml does a host rename, so reloading the host (which uses the original host name)
// should now return null.
assertThat(reloadResourceByUniqueId()).isNull();
assertThat(reloadResourceByForeignKey()).isNull();
// However, it should load correctly if we use the new name (taken from the xml).
HostResource renamedHost =
loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc());
loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc());
assertAboutHosts().that(renamedHost)
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.HOST_UPDATE);
@ -127,7 +127,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.build());
clock.advanceOneMilli();
runFlow();
assertAboutEppResources().that(reloadResourceByUniqueId())
assertAboutEppResources().that(reloadResourceByForeignKey())
.doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED);
}
@ -175,7 +175,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
clock.advanceOneMilli();
runFlowAssertResponse(readFile("host_update_response.xml"));
// The example xml doesn't do a host rename, so reloading the host should work.
assertAboutHosts().that(reloadResourceByUniqueId())
assertAboutHosts().that(reloadResourceByForeignKey())
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.HOST_UPDATE);
assertDnsTasksEnqueued("ns1.example.tld");
@ -196,13 +196,13 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.setSubordinateHosts(ImmutableSet.of(oldHostName()))
.build());
assertThat(
loadByUniqueId(
loadByForeignKey(
DomainResource.class, "example.tld", clock.nowUtc()).getSubordinateHosts())
.containsExactly("ns1.example.tld");
HostResource renamedHost = doSuccessfulTest();
assertThat(renamedHost.getSuperordinateDomain()).isEqualTo(Key.create(domain));
assertThat(
loadByUniqueId(
loadByForeignKey(
DomainResource.class, "example.tld", clock.nowUtc()).getSubordinateHosts())
.containsExactly("ns2.example.tld");
assertDnsTasksEnqueued("ns1.example.tld", "ns2.example.tld");
@ -224,21 +224,21 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.setSubordinateHosts(ImmutableSet.of(oldHostName()))
.build());
assertThat(
loadByUniqueId(
loadByForeignKey(
DomainResource.class, "foo.tld", clock.nowUtc()).getSubordinateHosts())
.containsExactly("ns2.foo.tld");
assertThat(
loadByUniqueId(
loadByForeignKey(
DomainResource.class, "example.tld", clock.nowUtc()).getSubordinateHosts())
.isEmpty();
HostResource renamedHost = doSuccessfulTest();
assertThat(renamedHost.getSuperordinateDomain()).isEqualTo(Key.create(example));
assertThat(
loadByUniqueId(
loadByForeignKey(
DomainResource.class, "foo.tld", clock.nowUtc()).getSubordinateHosts())
.isEmpty();
assertThat(
loadByUniqueId(
loadByForeignKey(
DomainResource.class, "example.tld", clock.nowUtc()).getSubordinateHosts())
.containsExactly("ns2.example.tld");
assertDnsTasksEnqueued("ns2.foo.tld", "ns2.example.tld");
@ -259,7 +259,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.setSubordinateHosts(ImmutableSet.of(oldHostName()))
.build());
assertThat(
loadByUniqueId(
loadByForeignKey(
DomainResource.class, "example.foo", clock.nowUtc()).getSubordinateHosts())
.containsExactly("ns1.example.foo");
HostResource renamedHost = doSuccessfulTest();
@ -268,7 +268,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
// comes from the field on the host itself, because the superordinate domain is null).
assertThat(renamedHost.getCurrentSponsorClientId()).isEqualTo("TheRegistrar");
assertThat(
loadByUniqueId(
loadByForeignKey(
DomainResource.class, "example.foo", clock.nowUtc()).getSubordinateHosts())
.isEmpty();
assertDnsTasksEnqueued("ns1.example.foo");
@ -287,16 +287,16 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
DomainResource tldDomain = persistActiveDomain("example.tld");
persistActiveHost(oldHostName());
assertThat(loadByUniqueId(
assertThat(loadByForeignKey(
HostResource.class, oldHostName(), clock.nowUtc()).getCurrentSponsorClientId())
.isEqualTo("TheRegistrar");
assertThat(
loadByUniqueId(
loadByForeignKey(
DomainResource.class, "example.tld", clock.nowUtc()).getSubordinateHosts())
.isEmpty();
HostResource renamedHost = doSuccessfulTest();
assertThat(renamedHost.getSuperordinateDomain()).isEqualTo(Key.create(tldDomain));
assertThat(loadByUniqueId(
assertThat(loadByForeignKey(
DomainResource.class, "example.tld", clock.nowUtc()).getSubordinateHosts())
.containsExactly("ns2.example.tld");
assertDnsTasksEnqueued("ns2.example.tld");
@ -319,15 +319,15 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
DomainResource domain = persistActiveDomain("example.tld");
persistActiveHost(oldHostName());
assertThat(loadByUniqueId(
assertThat(loadByForeignKey(
HostResource.class, oldHostName(), clock.nowUtc()).getCurrentSponsorClientId())
.isEqualTo("TheRegistrar");
assertThat(loadByUniqueId(
assertThat(loadByForeignKey(
DomainResource.class, "example.tld", clock.nowUtc()).getSubordinateHosts())
.isEmpty();
HostResource renamedHost = doSuccessfulTest();
assertThat(renamedHost.getSuperordinateDomain()).isEqualTo(Key.create(domain));
assertThat(loadByUniqueId(
assertThat(loadByForeignKey(
DomainResource.class, "example.tld", clock.nowUtc()).getSubordinateHosts())
.containsExactly("ns2.example.tld");
assertDnsTasksEnqueued("ns2.example.tld");
@ -351,7 +351,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
CommitMode.LIVE,
UserPrivileges.SUPERUSER,
readFile("host_update_response.xml"));
assertAboutHosts().that(reloadResourceByUniqueId())
assertAboutHosts().that(reloadResourceByForeignKey())
.hasStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED).and()
.hasStatusValue(StatusValue.SERVER_UPDATE_PROHIBITED);
}
@ -893,7 +893,8 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
eppRequestSource = EppRequestSource.TOOL;
runFlowAssertResponse(readFile("host_update_response.xml"));
assertAboutHistoryEntries()
.that(getOnlyHistoryEntryOfType(reloadResourceByUniqueId(), HistoryEntry.Type.HOST_UPDATE))
.that(getOnlyHistoryEntryOfType(
reloadResourceByForeignKey(), HistoryEntry.Type.HOST_UPDATE))
.hasMetadataReason("host-update-test").and()
.hasMetadataRequestedByRegistrar(false);
}