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

@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Sets.difference;
import static google.registry.mapreduce.MapreduceRunner.PARAM_DRY_RUN;
import static google.registry.mapreduce.inputs.EppResourceInputs.createChildEntityInput;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.common.Cursor.CursorType.RECURRING_BILLING;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
@ -158,7 +158,7 @@ public class ExpandRecurringBillingEventsAction implements Runnable {
Iterable<OneTime> oneTimesForDomain = ofy().load()
.type(OneTime.class)
.ancestor(loadByUniqueId(
.ancestor(loadByForeignKey(
DomainResource.class, recurring.getTargetId(), executeTime));
// Determine the billing times that already have OneTime events persisted.

View file

@ -14,7 +14,7 @@
package google.registry.dns;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import google.registry.dns.DnsConstants.TargetType;
import google.registry.model.EppResource;
@ -58,7 +58,7 @@ public final class RefreshDnsAction implements Runnable {
throw new BadRequestException("Unsupported type: " + type);
}
EppResource eppResource = loadByUniqueId(clazz, domainOrHostName, clock.nowUtc());
EppResource eppResource = loadByForeignKey(clazz, domainOrHostName, clock.nowUtc());
if (eppResource == null) {
throw new NotFoundException(
String.format("%s %s not found", type, domainOrHostName));

View file

@ -15,7 +15,7 @@
package google.registry.dns.writer.clouddns;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo;
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
@ -110,7 +110,7 @@ class CloudDnsWriter implements DnsWriter {
// Load the target domain. Note that it can be null if this domain was just deleted.
Optional<DomainResource> domainResource =
Optional.fromNullable(loadByUniqueId(DomainResource.class, domainName, clock.nowUtc()));
Optional.fromNullable(loadByForeignKey(DomainResource.class, domainName, clock.nowUtc()));
// Return early if no DNS records should be published.
// desiredRecordsBuilder is populated with an empty set to indicate that all existing records
@ -180,7 +180,7 @@ class CloudDnsWriter implements DnsWriter {
// desiredRecords is populated with an empty set to indicate that all existing records
// should be deleted.
Optional<HostResource> host =
Optional.fromNullable(loadByUniqueId(HostResource.class, hostName, clock.nowUtc()));
Optional.fromNullable(loadByForeignKey(HostResource.class, hostName, clock.nowUtc()));
// Return early if the host is deleted.
if (!host.isPresent()) {

View file

@ -17,7 +17,7 @@ package google.registry.dns.writer.dnsupdate;
import static com.google.common.base.Verify.verify;
import static com.google.common.collect.Sets.intersection;
import static com.google.common.collect.Sets.union;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
@ -111,7 +111,7 @@ public class DnsUpdateWriter implements DnsWriter {
* this domain refresh request
*/
private void publishDomain(String domainName, String requestingHostName) {
DomainResource domain = loadByUniqueId(DomainResource.class, domainName, clock.nowUtc());
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, clock.nowUtc());
try {
Update update = new Update(toAbsoluteName(findTldFromName(domainName)));
update.delete(toAbsoluteName(domainName), Type.ANY);
@ -202,7 +202,7 @@ public class DnsUpdateWriter implements DnsWriter {
for (String hostName :
intersection(
domain.loadNameserverFullyQualifiedHostNames(), domain.getSubordinateHosts())) {
HostResource host = loadByUniqueId(HostResource.class, hostName, clock.nowUtc());
HostResource host = loadByForeignKey(HostResource.class, hostName, clock.nowUtc());
update.add(makeAddressSet(host));
update.add(makeV6AddressSet(host));
}

View file

@ -15,7 +15,7 @@
package google.registry.flows;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.EppResourceUtils.queryDomainsUsingResource;
import static google.registry.model.domain.DomainResource.extendRegistrationWithCap;
import static google.registry.model.ofy.ObjectifyService.ofy;
@ -287,7 +287,7 @@ public class ResourceFlowUtils {
public static <R extends EppResource> R loadResourceForQuery(
Class<R> clazz, String targetId, DateTime now) throws ResourceToQueryDoesNotExistException {
R resource = loadByUniqueId(clazz, targetId, now);
R resource = loadByForeignKey(clazz, targetId, now);
if (resource == null) {
throw new ResourceToQueryDoesNotExistException(clazz, targetId);
}
@ -296,7 +296,7 @@ public class ResourceFlowUtils {
public static <R extends EppResource> R loadResourceToMutate(
Class<R> clazz, String targetId, DateTime now) throws ResourceToMutateDoesNotExistException {
R resource = loadByUniqueId(clazz, targetId, now);
R resource = loadByForeignKey(clazz, targetId, now);
if (resource == null) {
throw new ResourceToMutateDoesNotExistException(clazz, targetId);
}
@ -305,7 +305,7 @@ public class ResourceFlowUtils {
public static <R extends EppResource> void verifyResourceDoesNotExist(
Class<R> clazz, String targetId, DateTime now) throws EppException {
if (loadByUniqueId(clazz, targetId, now) != null) {
if (loadByForeignKey(clazz, targetId, now) != null) {
throw new ResourceAlreadyExistsException(targetId);
}
}

View file

@ -14,13 +14,15 @@
package google.registry.flows;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import google.registry.flows.EppException.StatusProhibitsOperationException;
import google.registry.model.EppResource;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.launch.ApplicationIdTargetExtension;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.eppinput.ResourceCommand.SingleResourceCommand;
@ -38,6 +40,7 @@ public abstract class SingleResourceFlow<R extends EppResource, C extends Single
protected R existingResource;
protected String targetId;
@SuppressWarnings("unchecked")
@Override
protected final void initResourceFlow() throws EppException {
targetId = getTargetId();
@ -48,9 +51,14 @@ public abstract class SingleResourceFlow<R extends EppResource, C extends Single
// Some flows such as DomainApplicationInfoFlow have the id marked as optional in the schema.
// We require it by policy in the relevant flow, but here we need to make sure not to NPE when
// initializing the (obviously nonexistent) existing resource.
existingResource = (targetId == null || !tryToLoadExisting())
? null
: loadByUniqueId(resourceClass, targetId, now);
if (targetId != null && tryToLoadExisting()) {
// This ugliness goes away once domain application flows are flattened.
if (resourceClass == DomainApplication.class) {
existingResource = (R) loadDomainApplication(targetId, now);
} else {
existingResource = loadByForeignKey(resourceClass, targetId, now);
}
}
if (existingResource != null) {
Set<StatusValue> problems = Sets.intersection(
existingResource.getStatusValues(), getDisallowedStatuses());

View file

@ -32,7 +32,7 @@ import static google.registry.flows.domain.DomainFlowUtils.verifyPremiumNameIsNo
import static google.registry.flows.domain.DomainFlowUtils.verifySignedMarks;
import static google.registry.flows.domain.DomainFlowUtils.verifyUnitIsYears;
import static google.registry.model.EppResourceUtils.createDomainRoid;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.domain.fee.Fee.FEE_CREATE_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registries.findTldForName;
@ -164,7 +164,7 @@ public abstract class BaseDomainCreateFlow<R extends DomainBase, B extends Build
@Override
public DomainResource run() {
// This is cacheable because we are outside of a transaction.
return loadByUniqueId(DomainResource.class, targetId, now);
return loadByForeignKey(DomainResource.class, targetId, now);
}});
// If the domain exists already and isn't in the ADD grace period then there is no way it will
// be suddenly deleted and therefore the create must fail.

View file

@ -16,7 +16,7 @@ package google.registry.flows.domain;
import static com.google.common.base.Preconditions.checkNotNull;
import static google.registry.flows.domain.DomainFlowUtils.getReservationType;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
import static google.registry.util.CollectionUtils.isNullOrEmpty;
@ -75,7 +75,7 @@ public class DomainAllocateFlow extends DomainCreateOrAllocateFlow {
throw new OnlySuperuserCanAllocateException();
}
String applicationRoid = allocateCreate.getApplicationRoid();
application = loadByUniqueId(DomainApplication.class, applicationRoid, now);
application = loadDomainApplication(applicationRoid, now);
if (application == null) {
throw new MissingApplicationException(applicationRoid);
}

View file

@ -15,11 +15,11 @@
package google.registry.flows.domain;
import static google.registry.flows.EppXmlTransformer.unmarshal;
import static google.registry.flows.ResourceFlowUtils.loadResourceForQuery;
import static google.registry.flows.ResourceFlowUtils.verifyOptionalAuthInfoForResource;
import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership;
import static google.registry.flows.domain.DomainFlowUtils.addSecDnsExtensionIfPresent;
import static google.registry.flows.domain.DomainFlowUtils.verifyApplicationDomainMatchesTargetId;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
import com.google.common.base.Optional;
@ -31,6 +31,7 @@ import google.registry.flows.FlowModule.ApplicationId;
import google.registry.flows.FlowModule.ClientId;
import google.registry.flows.FlowModule.TargetId;
import google.registry.flows.LoggedInFlow;
import google.registry.flows.exceptions.ResourceToQueryDoesNotExistException;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.DomainCommand.Info;
import google.registry.model.domain.launch.LaunchInfoExtension;
@ -75,8 +76,10 @@ public final class DomainApplicationInfoFlow extends LoggedInFlow {
if (applicationId.isEmpty()) {
throw new MissingApplicationIdException();
}
DomainApplication application =
loadResourceForQuery(DomainApplication.class, applicationId, now);
DomainApplication application = loadDomainApplication(applicationId, now);
if (application == null) {
throw new ResourceToQueryDoesNotExistException(DomainApplication.class, applicationId);
}
verifyApplicationDomainMatchesTargetId(application, targetId);
verifyOptionalAuthInfoForResource(authInfo, application);
LaunchInfoExtension launchInfo = eppInput.getSingleExtension(LaunchInfoExtension.class);

View file

@ -15,7 +15,7 @@
package google.registry.flows.domain;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName;
import static google.registry.util.CollectionUtils.nullToEmpty;
@ -181,7 +181,7 @@ public final class TldSpecificLogicProxy {
RegistryExtraFlowLogicProxy.newInstanceForTld(registry.getTldStr());
if (extraFlowLogic.isPresent()) {
// TODO: Consider changing the method definition to have the domain passed in to begin with.
DomainResource domain = loadByUniqueId(DomainResource.class, domainName, date);
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, date);
if (domain == null) {
throw new ResourceToMutateDoesNotExistException(DomainResource.class, domainName);
}
@ -247,7 +247,7 @@ public final class TldSpecificLogicProxy {
RegistryExtraFlowLogicProxy.newInstanceForTld(registry.getTldStr());
if (extraFlowLogic.isPresent()) {
// TODO: Consider changing the method definition to have the domain passed in to begin with.
DomainResource domain = loadByUniqueId(DomainResource.class, domainName, date);
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, date);
if (domain == null) {
throw new ResourceToMutateDoesNotExistException(DomainResource.class, domainName);
}

View file

@ -15,7 +15,7 @@
package google.registry.flows.host;
import static google.registry.model.EppResourceUtils.isActive;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.registry.Registries.findTldForName;
import com.google.common.base.Joiner;
@ -84,7 +84,7 @@ public class HostFlowUtils {
// This is a subordinate host
String domainName = Joiner.on('.').join(Iterables.skip(
hostName.parts(), hostName.parts().size() - (tld.get().parts().size() + 1)));
DomainResource superordinateDomain = loadByUniqueId(DomainResource.class, domainName, now);
DomainResource superordinateDomain = loadByForeignKey(DomainResource.class, domainName, now);
if (superordinateDomain == null || !isActive(superordinateDomain, now)) {
throw new SuperordinateDomainDoesNotExistException(domainName);
}

View file

@ -31,6 +31,7 @@ import google.registry.config.RegistryEnvironment;
import google.registry.model.EppResource.Builder;
import google.registry.model.EppResource.ForeignKeyedEppResource;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.DomainBase;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
@ -84,40 +85,29 @@ public final class EppResourceUtils {
*
* <p>Loading an {@link EppResource} by itself is not sufficient to know its current state since
* it may have various expirable conditions and status values that might implicitly change its
* state as time progresses even if it has not been updated in the datastore. Rather, the
* resource must be combined with a timestamp to view its current state. We use a global last
* updated timestamp on the entire entity group (which is essentially free since all writes to
* the entity group must be serialized anyways) to guarantee monotonically increasing write
* times, so forwarding our projected time to the greater of "now", and this update timestamp
* guarantees that we're not projecting into the past.
* state as time progresses even if it has not been updated in the datastore. Rather, the resource
* must be combined with a timestamp to view its current state. We use a global last updated
* timestamp on the entire entity group (which is essentially free since all writes to the entity
* group must be serialized anyways) to guarantee monotonically increasing write times, so
* forwarding our projected time to the greater of "now", and this update timestamp guarantees
* that we're not projecting into the past.
*
* @param clazz the resource type to load
* @param foreignKey id to match
* @param now the current logical time to project resources at
*/
public static <T extends EppResource> T loadByUniqueId(
@Nullable
public static <T extends EppResource> T loadByForeignKey(
Class<T> clazz, String foreignKey, DateTime now) {
// For regular foreign-keyed resources, get the key by loading the FKI; for domain applications,
// we can construct the key directly, since the provided foreignKey is just the repoId.
Key<T> resourceKey = ForeignKeyedEppResource.class.isAssignableFrom(clazz)
? loadAndGetKey(clazz, foreignKey, now)
: Key.create(null, clazz, foreignKey);
checkArgument(
ForeignKeyedEppResource.class.isAssignableFrom(clazz),
"loadByForeignKey may only be called for foreign keyed EPP resources");
Key<T> resourceKey = loadAndGetKey(clazz, foreignKey, now);
if (resourceKey == null) {
return null;
}
T resource = ofy().load().key(resourceKey).now();
if (resource == null
// You'd think this couldn't happen, but it can. For polymorphic entities, a Key is of
// necessity a reference to the base type (since datastore doesn't have polymorphism and
// Objectify is faking it). In the non-foreign-key code path above where we directly create
// a Key, there is no way to know whether the Key points to an instance of the desired
// subclass without loading it. Due to type erasure, it gets stuffed into "resource" without
// causing a ClassCastException even if it's the wrong type until you actually try to use it
// as the wrong type, at which point it blows up somewhere else in the code. Concretely,
// this means that without this line bad things would happen if you tried to load a
// DomainApplication using the id of a DomainResource (but not vice versa).
|| !clazz.isInstance(resource)
|| isAtOrAfter(now, resource.getDeletionTime())) {
if (resource == null || isAtOrAfter(now, resource.getDeletionTime())) {
return null;
}
// When setting status values based on a time, choose the greater of "now" and the resource's
@ -127,8 +117,23 @@ public final class EppResourceUtils {
// fail when it tries to save anything via Ofy, since "now" is needed to be > the last update
// time for writes.
return cloneProjectedAtTime(
resource,
latestOf(now, resource.getUpdateAutoTimestamp().getTimestamp()));
resource, latestOf(now, resource.getUpdateAutoTimestamp().getTimestamp()));
}
/**
* Returns the domain application with the given application id if it exists, or null if it does
* not or is soft-deleted as of the given time.
*/
@Nullable
public static DomainApplication loadDomainApplication(String applicationId, DateTime now) {
DomainApplication application =
ofy().load().key(Key.create(DomainApplication.class, applicationId)).now();
if (application == null || isAtOrAfter(now, application.getDeletionTime())) {
return null;
}
// Applications don't have any speculative changes that become effective later, so no need to
// clone forward in time.
return application;
}
/**

View file

@ -14,7 +14,7 @@
package google.registry.rdap;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.HEAD;
@ -55,8 +55,7 @@ public class RdapDomainAction extends RdapActionBase {
pathSearchString = canonicalizeName(pathSearchString);
validateDomainName(pathSearchString);
// The query string is not used; the RDAP syntax is /rdap/domain/mydomain.com.
DomainResource domainResource =
loadByUniqueId(DomainResource.class, pathSearchString, now);
DomainResource domainResource = loadByForeignKey(DomainResource.class, pathSearchString, now);
if (domainResource == null) {
throw new NotFoundException(pathSearchString + " not found");
}

View file

@ -14,7 +14,7 @@
package google.registry.rdap;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.request.Action.Method.GET;
@ -136,7 +136,7 @@ public class RdapDomainSearchAction extends RdapActionBase {
// Handle queries without a wildcard -- just load by foreign key.
if (!partialStringQuery.getHasWildcard()) {
DomainResource domainResource =
loadByUniqueId(DomainResource.class, partialStringQuery.getInitialString(), now);
loadByForeignKey(DomainResource.class, partialStringQuery.getInitialString(), now);
if (domainResource == null) {
return ImmutableList.of();
}
@ -222,7 +222,7 @@ public class RdapDomainSearchAction extends RdapActionBase {
// differently. We use the suffix to look up the domain, then loop through the subordinate hosts
// looking for matches.
} else {
DomainResource domainResource = loadByUniqueId(
DomainResource domainResource = loadByForeignKey(
DomainResource.class, partialStringQuery.getSuffix(), now);
if (domainResource == null) {
throw new NotFoundException("No domain found for specified nameserver suffix");

View file

@ -14,7 +14,7 @@
package google.registry.rdap;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.HEAD;
@ -55,8 +55,7 @@ public class RdapNameserverAction extends RdapActionBase {
pathSearchString = canonicalizeName(pathSearchString);
// The RDAP syntax is /rdap/nameserver/ns1.mydomain.com.
validateDomainName(pathSearchString);
HostResource hostResource =
loadByUniqueId(HostResource.class, pathSearchString, now);
HostResource hostResource = loadByForeignKey(HostResource.class, pathSearchString, now);
if (hostResource == null) {
throw new NotFoundException(pathSearchString + " not found");
}

View file

@ -14,7 +14,7 @@
package google.registry.rdap;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.HEAD;
@ -118,7 +118,7 @@ public class RdapNameserverSearchAction extends RdapActionBase {
// Handle queries without a wildcard -- just load by foreign key.
if (!partialStringQuery.getHasWildcard()) {
HostResource hostResource =
loadByUniqueId(HostResource.class, partialStringQuery.getInitialString(), now);
loadByForeignKey(HostResource.class, partialStringQuery.getInitialString(), now);
if (hostResource == null) {
throw new NotFoundException("No nameservers found");
}
@ -141,7 +141,7 @@ public class RdapNameserverSearchAction extends RdapActionBase {
// looking for matches.
} else {
DomainResource domainResource =
loadByUniqueId(DomainResource.class, partialStringQuery.getSuffix(), now);
loadByForeignKey(DomainResource.class, partialStringQuery.getSuffix(), now);
if (domainResource == null) {
throw new NotFoundException("No domain found for specified nameserver suffix");
}
@ -150,7 +150,7 @@ public class RdapNameserverSearchAction extends RdapActionBase {
// We can't just check that the host name starts with the initial query string, because then
// the query ns.exam*.example.com would match against nameserver ns.example.com.
if (partialStringQuery.matches(fqhn)) {
HostResource hostResource = loadByUniqueId(HostResource.class, fqhn, now);
HostResource hostResource = loadByForeignKey(HostResource.class, fqhn, now);
if (hostResource != null) {
hostListBuilder.add(hostResource);
}

View file

@ -15,13 +15,15 @@
package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.googlecode.objectify.Key;
import google.registry.model.EppResource;
import google.registry.model.domain.DomainApplication;
import google.registry.tools.Command.RemoteApiCommand;
import google.registry.util.TypeUtils.TypeInstantiator;
import org.joda.time.DateTime;
@ -32,8 +34,7 @@ import org.joda.time.DateTime;
* @param <R> {@link EppResource} subclass.
*/
@Parameters(separators = " =")
abstract class GetEppResourceCommand<R extends EppResource>
implements RemoteApiCommand {
abstract class GetEppResourceCommand<R extends EppResource> implements RemoteApiCommand {
private final DateTime now = DateTime.now(UTC);
@ -57,7 +58,10 @@ abstract class GetEppResourceCommand<R extends EppResource>
* manual mapreduce calls.
*/
void printResource(String uniqueId) {
R resource = loadByUniqueId(clazz, uniqueId, readTimestamp);
EppResource resource =
(clazz == DomainApplication.class)
? loadDomainApplication(uniqueId, readTimestamp)
: loadByForeignKey(clazz, uniqueId, readTimestamp);
System.out.println(resource != null
? String.format("%s\n\nWebsafe key: %s",
expand ? resource.toHydratedString() : resource,

View file

@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.collect.Sets.difference;
import static google.registry.model.EppResourceUtils.checkResourcesExist;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static org.joda.time.DateTimeZone.UTC;
@ -120,7 +120,7 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand impleme
} catch (ClassCastException | ParseException e) {
throw new IllegalArgumentException("Invalid --dsdata JSON", e);
}
DomainResource domain = loadByUniqueId(DomainResource.class, domainName, now);
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, now);
checkArgument(domain != null, "Domain '%s' does not exist", domainName);
Set<String> missingHosts =
difference(newHostsSet, checkResourcesExist(HostResource.class, newHosts, now));

View file

@ -16,7 +16,7 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.domain.launch.ApplicationStatus.ALLOCATED;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
@ -89,8 +89,7 @@ final class UpdateApplicationStatusCommand extends MutatingCommand {
DateTime now = ofy().getTransactionTime();
// Load the domain application.
DomainApplication domainApplication =
loadByUniqueId(DomainApplication.class, applicationId, now);
DomainApplication domainApplication = loadDomainApplication(applicationId, now);
checkArgumentNotNull(domainApplication, "Domain application does not exist");
// It's not an error if the application already has the intended status. We want the method

View file

@ -15,7 +15,7 @@
package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.ofy.ObjectifyService.ofy;
import com.beust.jcommander.Parameter;
@ -84,8 +84,7 @@ final class UpdateClaimsNoticeCommand implements RemoteApiCommand {
DateTime now = ofy().getTransactionTime();
// Load the domain application.
DomainApplication domainApplication =
loadByUniqueId(DomainApplication.class, applicationId, now);
DomainApplication domainApplication = loadDomainApplication(applicationId, now);
checkArgument(domainApplication != null, "Domain application does not exist");
// Make sure this isn't a sunrise application.

View file

@ -16,7 +16,7 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.flows.domain.DomainFlowUtils.verifyEncodedSignedMark;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.tmch.TmchData.readEncodedSignedMark;
import static java.nio.charset.StandardCharsets.US_ASCII;
@ -81,8 +81,7 @@ final class UpdateSmdCommand implements RemoteApiCommand {
DateTime now = ofy().getTransactionTime();
// Load the domain application.
DomainApplication domainApplication =
loadByUniqueId(DomainApplication.class, applicationId, now);
DomainApplication domainApplication = loadDomainApplication(applicationId, now);
checkArgument(domainApplication != null, "Domain application does not exist");
// Make sure this is a sunrise application.

View file

@ -15,7 +15,8 @@
package google.registry.tools.javascrap;
import static com.google.common.collect.Maps.uniqueIndex;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static org.joda.time.DateTimeZone.UTC;
@ -32,7 +33,7 @@ import java.util.Arrays;
import java.util.Map;
import org.joda.time.DateTime;
/** Load and resave an object in the probers, to trigger @OnSave changes. */
/** A command to load and resave an entity, which triggers @OnSave changes. */
@Parameters(
separators = " =",
commandDescription = "Load and resave an object, to trigger @OnSave changes")
@ -45,9 +46,9 @@ public final class LoadAndResaveCommand extends MutatingCommand {
protected String type;
@Parameter(
names = "--key",
description = "Foreign key of the resource. ")
protected String foreignKey;
names = "--id",
description = "Foreign key of the resource, or application ID of the domain application.")
protected String uniqueId;
private static final Map<String, Class<? extends EppResource>> CLASSES_BY_NAME =
uniqueIndex(
@ -64,12 +65,15 @@ public final class LoadAndResaveCommand extends MutatingCommand {
@Override
protected void init() throws Exception {
Class<? extends EppResource> clazz = CLASSES_BY_NAME.get(type);
EppResource existing =
(clazz == DomainApplication.class)
? loadDomainApplication(uniqueId, DateTime.now(UTC))
: loadByForeignKey(clazz, uniqueId, DateTime.now(UTC));
// Find the resource by foreign key, and then reload it directly, bypassing loadByUniqueId().
// We need to do a reload because otherwise stageEntityChange() can fail due to the implicit
// changes done when forwarding the resource to "now" in cloneProjectedAtTime().
EppResource resource = ofy().load().entity(
loadByUniqueId(CLASSES_BY_NAME.get(type), foreignKey, DateTime.now(UTC))).now();
EppResource resource = ofy().load().entity(existing).now();
stageEntityChange(resource, resource);
}
}

View file

@ -15,7 +15,7 @@
package google.registry.whois;
import static com.google.common.base.Preconditions.checkNotNull;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.registry.Registries.findTldForName;
import static google.registry.model.registry.Registries.getTlds;
import static javax.servlet.http.HttpServletResponse.SC_NOT_FOUND;
@ -52,7 +52,7 @@ abstract class DomainOrHostLookupCommand<T extends EppResource> implements Whois
}
// Google Policy: Do not return records under TLDs for which we're not authoritative.
if (tld.isPresent() && getTlds().contains(tld.get().toString())) {
T domainOrHost = loadByUniqueId(
T domainOrHost = loadByForeignKey(
new TypeInstantiator<T>(getClass()){}.getExactType(),
domainOrHostName.toString(),
now);

View file

@ -15,7 +15,7 @@
package google.registry.flows;
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.model.ofy.ObjectifyService.ofy;
import static google.registry.model.tmch.ClaimsListShardTest.createTestClaimsListShard;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
@ -27,6 +27,8 @@ import com.google.common.collect.ImmutableMap;
import com.googlecode.objectify.Key;
import google.registry.flows.EppException.CommandUseErrorException;
import google.registry.model.EppResource;
import google.registry.model.EppResourceUtils;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.launch.ApplicationIdTargetExtension;
import google.registry.model.eppinput.EppInput.ResourceCommandWrapper;
import google.registry.model.eppinput.ResourceCommand;
@ -54,19 +56,20 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
@Rule
public final ExceptionRule thrown = new ExceptionRule();
private R reloadResourceByUniqueId(DateTime now) throws Exception {
protected R reloadResourceByForeignKey(DateTime now) throws Exception {
// Force the session to be cleared so that when we read it back, we read from the datastore and
// not from the transaction cache or memcache.
ofy().clearSessionCache();
return loadByUniqueId(getResourceClass(), getUniqueIdFromCommand(), now);
return loadByForeignKey(getResourceClass(), getUniqueIdFromCommand(), now);
}
protected R reloadResourceByUniqueId() throws Exception {
return reloadResourceByUniqueId(clock.nowUtc());
protected R reloadResourceByForeignKey() throws Exception {
return reloadResourceByForeignKey(clock.nowUtc());
}
protected R reloadResourceByUniqueIdYesterday() throws Exception {
return reloadResourceByUniqueId(clock.nowUtc().minusDays(1));
protected DomainApplication reloadDomainApplication() throws Exception {
ofy().clearSessionCache();
return EppResourceUtils.loadDomainApplication(getUniqueIdFromCommand(), clock.nowUtc());
}
protected <T extends EppResource> T reloadResourceAndCloneAtTime(T resource, DateTime now) {

View file

@ -15,7 +15,7 @@
package google.registry.flows.async;
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.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
@ -70,10 +70,10 @@ public class DeleteContactResourceActionTest
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
runMapreduceWithKeyParam(Key.create(contactUsed).getString());
contactUsed = loadByUniqueId(ContactResource.class, "blah1234", now);
contactUsed = loadByForeignKey(ContactResource.class, "blah1234", now);
assertAboutContacts().that(contactUsed).doesNotHaveStatusValue(StatusValue.PENDING_DELETE)
.and().hasDeletionTime(END_OF_TIME);
domain = loadByUniqueId(DomainResource.class, "example.tld", now);
domain = loadByForeignKey(DomainResource.class, "example.tld", now);
assertThat(domain.getReferencedContacts()).contains(Key.create(contactUsed));
HistoryEntry historyEntry =
getOnlyHistoryEntryOfType(contactUsed, HistoryEntry.Type.CONTACT_DELETE_FAILURE);
@ -113,7 +113,7 @@ public class DeleteContactResourceActionTest
.and().hasNonNullFaxNumber();
Key<ContactResource> key = Key.create(contactUnused);
runMapreduceWithKeyParam(key.getString());
assertThat(loadByUniqueId(ContactResource.class, "blah1235", now)).isNull();
assertThat(loadByForeignKey(ContactResource.class, "blah1235", now)).isNull();
ContactResource contactAfterDeletion = ofy().load().key(key).now();
assertAboutContacts().that(contactAfterDeletion).hasDeletionTime(now)
// Note that there will be another history entry of CONTACT_PENDING_DELETE, but this is
@ -140,10 +140,10 @@ public class DeleteContactResourceActionTest
clock.nowUtc());
runMapreduceWithKeyParam(Key.create(contact).getString());
// Check that the contact is deleted as of now.
assertThat(loadByUniqueId(ContactResource.class, "sh8013", now)).isNull();
assertThat(loadByForeignKey(ContactResource.class, "sh8013", now)).isNull();
// Check that it's still there (it wasn't deleted yesterday) and that it has history.
assertAboutContacts()
.that(loadByUniqueId(ContactResource.class, "sh8013", now.minusDays(1)))
.that(loadByForeignKey(ContactResource.class, "sh8013", now.minusDays(1)))
.hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.CONTACT_TRANSFER_REQUEST,
HistoryEntry.Type.CONTACT_DELETE);
@ -181,9 +181,9 @@ public class DeleteContactResourceActionTest
.setDeletionTime(now.minusDays(3))
.build());
runMapreduceWithKeyParam(Key.create(contactUsed).getString());
assertThat(loadByUniqueId(ContactResource.class, "blah1234", now)).isNull();
assertThat(loadByForeignKey(ContactResource.class, "blah1234", now)).isNull();
ContactResource contactBeforeDeletion =
loadByUniqueId(ContactResource.class, "blah1234", now.minusDays(1));
loadByForeignKey(ContactResource.class, "blah1234", now.minusDays(1));
assertAboutContacts().that(contactBeforeDeletion).hasDeletionTime(now)
.and().hasExactlyStatusValues(StatusValue.OK)
// Note that there will be another history entry of CONTACT_PENDING_DELETE, but this is
@ -199,7 +199,7 @@ public class DeleteContactResourceActionTest
thrown.expect(IllegalStateException.class, "Resource blah1235 is not set as PENDING_DELETE");
runMapreduceWithKeyParam(Key.create(contactUnused).getString());
assertThat(
loadByUniqueId(ContactResource.class, "blah1235", now)).isEqualTo(contactUnused);
loadByForeignKey(ContactResource.class, "blah1235", now)).isEqualTo(contactUnused);
}
@Test
@ -210,10 +210,10 @@ public class DeleteContactResourceActionTest
.build());
Key<ContactResource> key = Key.create(contactUnused);
runMapreduceWithParams(key.getString(), "OtherRegistrar", false);
contactUnused = loadByUniqueId(ContactResource.class, "blah1235", now);
contactUnused = loadByForeignKey(ContactResource.class, "blah1235", now);
assertAboutContacts().that(contactUnused).doesNotHaveStatusValue(StatusValue.PENDING_DELETE)
.and().hasDeletionTime(END_OF_TIME);
domain = loadByUniqueId(DomainResource.class, "example.tld", now);
domain = loadByForeignKey(DomainResource.class, "example.tld", now);
HistoryEntry historyEntry =
getOnlyHistoryEntryOfType(contactUnused, HistoryEntry.Type.CONTACT_DELETE_FAILURE);
assertPollMessageFor(
@ -247,7 +247,7 @@ public class DeleteContactResourceActionTest
.build());
Key<ContactResource> key = Key.create(contactUnused);
runMapreduceWithParams(key.getString(), "OtherRegistrar", true);
assertThat(loadByUniqueId(ContactResource.class, "blah1235", now)).isNull();
assertThat(loadByForeignKey(ContactResource.class, "blah1235", now)).isNull();
ContactResource contactAfterDeletion = ofy().load().key(key).now();
assertAboutContacts().that(contactAfterDeletion).hasDeletionTime(now)
// Note that there will be another history entry of CONTACT_PENDING_DELETE, but this is

View file

@ -19,7 +19,7 @@ import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.async.DeleteContactsAndHostsAction.QUEUE_ASYNC_DELETE;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.eppcommon.StatusValue.PENDING_DELETE;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.reporting.HistoryEntry.Type.CONTACT_DELETE;
@ -154,14 +154,14 @@ public class DeleteContactsAndHostsActionTest
enqueuer.enqueueAsyncDelete(contact, "TheRegistrar", false);
runMapreduce();
ContactResource contactUpdated =
loadByUniqueId(ContactResource.class, "blah8221", clock.nowUtc());
loadByForeignKey(ContactResource.class, "blah8221", clock.nowUtc());
assertAboutContacts()
.that(contactUpdated)
.doesNotHaveStatusValue(PENDING_DELETE)
.and()
.hasDeletionTime(END_OF_TIME);
DomainResource domainReloaded =
loadByUniqueId(DomainResource.class, "example.tld", clock.nowUtc());
loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc());
assertThat(domainReloaded.getReferencedContacts()).contains(Key.create(contactUpdated));
HistoryEntry historyEntry =
getOnlyHistoryEntryOfType(contactUpdated, HistoryEntry.Type.CONTACT_DELETE_FAILURE);
@ -176,7 +176,7 @@ public class DeleteContactsAndHostsActionTest
ContactResource contact = persistContactWithPii("jim919");
enqueuer.enqueueAsyncDelete(contact, "TheRegistrar", false);
runMapreduce();
assertThat(loadByUniqueId(ContactResource.class, "jim919", clock.nowUtc())).isNull();
assertThat(loadByForeignKey(ContactResource.class, "jim919", clock.nowUtc())).isNull();
ContactResource contactAfterDeletion = ofy().load().entity(contact).now();
assertAboutContacts()
.that(contactAfterDeletion)
@ -213,10 +213,10 @@ public class DeleteContactsAndHostsActionTest
enqueuer.enqueueAsyncDelete(contact, "TheRegistrar", false);
runMapreduce();
// Check that the contact is deleted as of now.
assertThat(loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc())).isNull();
assertThat(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())).isNull();
// Check that it's still there (it wasn't deleted yesterday) and that it has history.
assertAboutContacts()
.that(loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc().minusDays(1)))
.that(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc().minusDays(1)))
.hasOneHistoryEntryEachOfTypes(CONTACT_TRANSFER_REQUEST, CONTACT_DELETE);
assertNoBillingEvents();
PollMessage deletePollMessage =
@ -252,9 +252,9 @@ public class DeleteContactsAndHostsActionTest
.build());
enqueuer.enqueueAsyncDelete(contactUsed, "TheRegistrar", false);
runMapreduce();
assertThat(loadByUniqueId(ContactResource.class, "blah1234", clock.nowUtc())).isNull();
assertThat(loadByForeignKey(ContactResource.class, "blah1234", clock.nowUtc())).isNull();
ContactResource contactBeforeDeletion =
loadByUniqueId(ContactResource.class, "blah1234", clock.nowUtc().minusDays(1));
loadByForeignKey(ContactResource.class, "blah1234", clock.nowUtc().minusDays(1));
assertAboutContacts()
.that(contactBeforeDeletion)
.isNotActiveAt(clock.nowUtc())
@ -276,9 +276,9 @@ public class DeleteContactsAndHostsActionTest
enqueuer.enqueueAsyncDelete(contact, "TheRegistrar", false);
enqueuer.enqueueAsyncDelete(host, "TheRegistrar", false);
runMapreduce();
assertThat(loadByUniqueId(ContactResource.class, "blah2222", clock.nowUtc()))
assertThat(loadByForeignKey(ContactResource.class, "blah2222", clock.nowUtc()))
.isEqualTo(contact);
assertThat(loadByUniqueId(HostResource.class, "rustles.your.jimmies", clock.nowUtc()))
assertThat(loadByForeignKey(HostResource.class, "rustles.your.jimmies", clock.nowUtc()))
.isEqualTo(host);
}
@ -288,7 +288,7 @@ public class DeleteContactsAndHostsActionTest
enqueuer.enqueueAsyncDelete(contact, "OtherRegistrar", false);
runMapreduce();
ContactResource contactAfter =
loadByUniqueId(ContactResource.class, "jane0991", clock.nowUtc());
loadByForeignKey(ContactResource.class, "jane0991", clock.nowUtc());
assertAboutContacts()
.that(contactAfter)
.doesNotHaveStatusValue(PENDING_DELETE)
@ -306,7 +306,7 @@ public class DeleteContactsAndHostsActionTest
ContactResource contact = persistContactWithPii("nate007");
enqueuer.enqueueAsyncDelete(contact, "OtherRegistrar", true);
runMapreduce();
assertThat(loadByUniqueId(ContactResource.class, "nate007", clock.nowUtc())).isNull();
assertThat(loadByForeignKey(ContactResource.class, "nate007", clock.nowUtc())).isNull();
ContactResource contactAfterDeletion = ofy().load().entity(contact).now();
assertAboutContacts()
.that(contactAfterDeletion)
@ -357,13 +357,14 @@ public class DeleteContactsAndHostsActionTest
persistUsedDomain("example.tld", persistActiveContact("abc456"), host);
enqueuer.enqueueAsyncDelete(host, "TheRegistrar", false);
runMapreduce();
HostResource hostAfter = loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc());
HostResource hostAfter =
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc());
assertAboutHosts()
.that(hostAfter)
.doesNotHaveStatusValue(PENDING_DELETE)
.and()
.hasDeletionTime(END_OF_TIME);
DomainResource domain = loadByUniqueId(DomainResource.class, "example.tld", clock.nowUtc());
DomainResource domain = loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc());
assertThat(domain.getNameservers()).contains(Key.create(hostAfter));
HistoryEntry historyEntry = getOnlyHistoryEntryOfType(hostAfter, HOST_DELETE_FAILURE);
assertPollMessageFor(
@ -377,9 +378,9 @@ public class DeleteContactsAndHostsActionTest
HostResource host = persistHostPendingDelete("ns2.example.tld");
enqueuer.enqueueAsyncDelete(host, "TheRegistrar", false);
runMapreduce();
assertThat(loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc())).isNull();
assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc())).isNull();
HostResource hostBeforeDeletion =
loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1));
loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1));
assertAboutHosts()
.that(hostBeforeDeletion)
.isNotActiveAt(clock.nowUtc())
@ -405,9 +406,9 @@ public class DeleteContactsAndHostsActionTest
.build());
enqueuer.enqueueAsyncDelete(host, "TheRegistrar", false);
runMapreduce();
assertThat(loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc())).isNull();
assertThat(loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())).isNull();
HostResource hostBeforeDeletion =
loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc().minusDays(1));
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc().minusDays(1));
assertAboutHosts()
.that(hostBeforeDeletion)
.isNotActiveAt(clock.nowUtc())
@ -439,15 +440,15 @@ public class DeleteContactsAndHostsActionTest
enqueuer.enqueueAsyncDelete(host, "TheRegistrar", false);
runMapreduce();
// Check that the host is deleted as of now.
assertThat(loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc())).isNull();
assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc())).isNull();
assertNoBillingEvents();
assertThat(
loadByUniqueId(DomainResource.class, "example.tld", clock.nowUtc())
loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc())
.getSubordinateHosts())
.isEmpty();
assertDnsTasksEnqueued("ns2.example.tld");
HostResource hostBeforeDeletion =
loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1));
loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1));
assertAboutHosts()
.that(hostBeforeDeletion)
.isNotActiveAt(clock.nowUtc())
@ -465,7 +466,8 @@ public class DeleteContactsAndHostsActionTest
HostResource host = persistHostPendingDelete("ns2.example.tld");
enqueuer.enqueueAsyncDelete(host, "OtherRegistrar", false);
runMapreduce();
HostResource hostAfter = loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc());
HostResource hostAfter =
loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc());
assertAboutHosts()
.that(hostAfter)
.doesNotHaveStatusValue(PENDING_DELETE)
@ -483,9 +485,9 @@ public class DeleteContactsAndHostsActionTest
HostResource host = persistHostPendingDelete("ns66.example.tld");
enqueuer.enqueueAsyncDelete(host, "OtherRegistrar", true);
runMapreduce();
assertThat(loadByUniqueId(HostResource.class, "ns66.example.tld", clock.nowUtc())).isNull();
assertThat(loadByForeignKey(HostResource.class, "ns66.example.tld", clock.nowUtc())).isNull();
HostResource hostBeforeDeletion =
loadByUniqueId(HostResource.class, "ns66.example.tld", clock.nowUtc().minusDays(1));
loadByForeignKey(HostResource.class, "ns66.example.tld", clock.nowUtc().minusDays(1));
assertAboutHosts()
.that(hostBeforeDeletion)
.isNotActiveAt(clock.nowUtc())

View file

@ -15,7 +15,7 @@
package google.registry.flows.async;
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.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.getOnlyPollMessageForHistoryEntry;
@ -127,7 +127,7 @@ public abstract class DeleteEppResourceActionTestCase<T extends DeleteEppResourc
thrown.expect(
IllegalArgumentException.class, "Cannot delete a DomainResource via this action.");
runMapreduceWithKeyParam(Key.create(domain).getString());
assertThat(loadByUniqueId(DomainResource.class, "fail.tld", now)).isEqualTo(domain);
assertThat(loadByForeignKey(DomainResource.class, "fail.tld", now)).isEqualTo(domain);
}
@Test

View file

@ -15,7 +15,7 @@
package google.registry.flows.async;
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.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.getOnlyHistoryEntryOfType;
@ -59,10 +59,10 @@ public class DeleteHostResourceActionTest
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
runMapreduceWithKeyParam(Key.create(hostUsed).getString());
hostUsed = loadByUniqueId(HostResource.class, "ns1.example.tld", now);
hostUsed = loadByForeignKey(HostResource.class, "ns1.example.tld", now);
assertAboutHosts().that(hostUsed).doesNotHaveStatusValue(StatusValue.PENDING_DELETE)
.and().hasDeletionTime(END_OF_TIME);
domain = loadByUniqueId(DomainResource.class, "example.tld", now);
domain = loadByForeignKey(DomainResource.class, "example.tld", now);
assertThat(domain.getNameservers()).contains(Key.create(hostUsed));
HistoryEntry historyEntry =
getOnlyHistoryEntryOfType(hostUsed, HistoryEntry.Type.HOST_DELETE_FAILURE);
@ -79,9 +79,9 @@ public class DeleteHostResourceActionTest
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
runMapreduceWithKeyParam(Key.create(hostUnused).getString());
assertThat(loadByUniqueId(HostResource.class, "ns2.example.tld", now)).isNull();
assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", now)).isNull();
HostResource hostBeforeDeletion =
loadByUniqueId(HostResource.class, "ns2.example.tld", now.minusDays(1));
loadByForeignKey(HostResource.class, "ns2.example.tld", now.minusDays(1));
assertAboutHosts().that(hostBeforeDeletion).hasDeletionTime(now)
.and().hasExactlyStatusValues(StatusValue.OK)
// Note that there will be another history entry of HOST_PENDING_DELETE, but this is
@ -103,9 +103,9 @@ public class DeleteHostResourceActionTest
.setDeletionTime(now.minusDays(3))
.build());
runMapreduceWithKeyParam(Key.create(hostUsed).getString());
assertThat(loadByUniqueId(HostResource.class, "ns1.example.tld", now)).isNull();
assertThat(loadByForeignKey(HostResource.class, "ns1.example.tld", now)).isNull();
HostResource hostBeforeDeletion =
loadByUniqueId(HostResource.class, "ns1.example.tld", now.minusDays(1));
loadByForeignKey(HostResource.class, "ns1.example.tld", now.minusDays(1));
assertAboutHosts().that(hostBeforeDeletion).hasDeletionTime(now)
.and().hasExactlyStatusValues(StatusValue.OK)
// Note that there will be another history entry of HOST_PENDING_DELETE, but this is
@ -129,15 +129,15 @@ public class DeleteHostResourceActionTest
.build());
runMapreduceWithKeyParam(Key.create(hostUnused).getString());
// Check that the host is deleted as of now.
assertThat(loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc()))
assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc()))
.isNull();
assertNoBillingEvents();
assertThat(loadByUniqueId(DomainResource.class, "example.tld", clock.nowUtc())
assertThat(loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc())
.getSubordinateHosts())
.isEmpty();
assertDnsTasksEnqueued("ns2.example.tld");
HostResource hostBeforeDeletion =
loadByUniqueId(HostResource.class, "ns2.example.tld", now.minusDays(1));
loadByForeignKey(HostResource.class, "ns2.example.tld", now.minusDays(1));
assertAboutHosts().that(hostBeforeDeletion).hasDeletionTime(now)
.and().hasExactlyStatusValues(StatusValue.OK)
.and().hasOnlyOneHistoryEntryWhich().hasType(HistoryEntry.Type.HOST_DELETE);
@ -152,7 +152,7 @@ public class DeleteHostResourceActionTest
IllegalStateException.class, "Resource ns2.example.tld is not set as PENDING_DELETE");
runMapreduceWithKeyParam(Key.create(hostUnused).getString());
assertThat(
loadByUniqueId(HostResource.class, "ns2.example.tld", now)).isEqualTo(hostUnused);
loadByForeignKey(HostResource.class, "ns2.example.tld", now)).isEqualTo(hostUnused);
}
@Test
@ -163,10 +163,10 @@ public class DeleteHostResourceActionTest
.build());
Key<HostResource> key = Key.create(hostUnused);
runMapreduceWithParams(key.getString(), "OtherRegistrar", false);
hostUnused = loadByUniqueId(HostResource.class, "ns2.example.tld", now);
hostUnused = loadByForeignKey(HostResource.class, "ns2.example.tld", now);
assertAboutHosts().that(hostUnused).doesNotHaveStatusValue(StatusValue.PENDING_DELETE)
.and().hasDeletionTime(END_OF_TIME);
domain = loadByUniqueId(DomainResource.class, "example.tld", now);
domain = loadByForeignKey(DomainResource.class, "example.tld", now);
HistoryEntry historyEntry =
getOnlyHistoryEntryOfType(hostUnused, HistoryEntry.Type.HOST_DELETE_FAILURE);
assertPollMessageFor(
@ -183,9 +183,9 @@ public class DeleteHostResourceActionTest
.build());
Key<HostResource> key = Key.create(hostUnused);
runMapreduceWithParams(key.getString(), "OtherRegistrar", true);
assertThat(loadByUniqueId(HostResource.class, "ns2.example.tld", now)).isNull();
assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", now)).isNull();
HostResource hostBeforeDeletion =
loadByUniqueId(HostResource.class, "ns2.example.tld", now.minusDays(1));
loadByForeignKey(HostResource.class, "ns2.example.tld", now.minusDays(1));
assertAboutHosts().that(hostBeforeDeletion).hasDeletionTime(now)
.and().hasExactlyStatusValues(StatusValue.OK)
// Note that there will be another history entry of HOST_PENDING_DELETE, but this is

View file

@ -40,10 +40,10 @@ public class ContactCreateFlowTest
assertTransactionalFlow(true);
runFlowAssertResponse(readFile("contact_create_response.xml"));
// Check that the contact was created and persisted with a history entry.
assertAboutContacts().that(reloadResourceByUniqueId())
assertAboutContacts().that(reloadResourceByForeignKey())
.hasOnlyOneHistoryEntryWhich().hasNoXml();
assertNoBillingEvents();
assertEppResourceIndexEntityFor(reloadResourceByUniqueId());
assertEppResourceIndexEntityFor(reloadResourceByForeignKey());
}
@Test

View file

@ -66,7 +66,7 @@ public class ContactDeleteFlowTest
clock.advanceOneMilli();
assertTransactionalFlow(true);
runFlowAssertResponse(readFile("contact_delete_response.xml"));
ContactResource deletedContact = reloadResourceByUniqueId();
ContactResource deletedContact = reloadResourceByForeignKey();
assertAboutContacts().that(deletedContact).hasStatusValue(StatusValue.PENDING_DELETE);
assertAsyncDeletionTaskEnqueued(deletedContact, "TheRegistrar", false);
assertAboutContacts().that(deletedContact)
@ -125,7 +125,7 @@ public class ContactDeleteFlowTest
clock.advanceOneMilli();
runFlowAssertResponse(
CommitMode.LIVE, UserPrivileges.SUPERUSER, readFile("contact_delete_response.xml"));
ContactResource deletedContact = reloadResourceByUniqueId();
ContactResource deletedContact = reloadResourceByForeignKey();
assertAboutContacts().that(deletedContact).hasStatusValue(StatusValue.PENDING_DELETE);
assertAsyncDeletionTaskEnqueued(deletedContact, "NewRegistrar", true);
assertAboutContacts().that(deletedContact)

View file

@ -68,7 +68,7 @@ public class ContactTransferApproveFlowTest
runFlowAssertResponse(readFile(expectedXmlFilename));
// Transfer should have succeeded. Verify correct fields were set.
contact = reloadResourceByUniqueId();
contact = reloadResourceByForeignKey();
assertAboutContacts().that(contact)
.hasCurrentSponsorClientId("NewRegistrar").and()
.hasLastTransferTime(clock.nowUtc()).and()

View file

@ -62,7 +62,7 @@ public class ContactTransferCancelFlowTest
runFlowAssertResponse(readFile(expectedXmlFilename));
// Transfer should have been cancelled. Verify correct fields were set.
contact = reloadResourceByUniqueId();
contact = reloadResourceByForeignKey();
assertAboutContacts().that(contact)
.hasCurrentSponsorClientId("TheRegistrar").and()
.hasLastTransferTimeNotEqualTo(clock.nowUtc()).and()

View file

@ -51,7 +51,7 @@ public class ContactTransferQueryFlowTest
// Setup done; run the test.
assertTransactionalFlow(false);
runFlowAssertResponse(readFile(expectedXmlFilename));
assertAboutContacts().that(reloadResourceByUniqueIdYesterday())
assertAboutContacts().that(reloadResourceByForeignKey(clock.nowUtc().minusDays(1)))
.hasOneHistoryEntryEachOfTypes(HistoryEntry.Type.CONTACT_TRANSFER_REQUEST);
assertNoBillingEvents();
}

View file

@ -66,7 +66,7 @@ public class ContactTransferRejectFlowTest
runFlowAssertResponse(readFile(expectedXmlFilename));
// Transfer should have failed. Verify correct fields were set.
contact = reloadResourceByUniqueId();
contact = reloadResourceByForeignKey();
assertAboutContacts().that(contact)
.hasCurrentSponsorClientId("TheRegistrar").and()
.hasLastTransferTimeNotEqualTo(clock.nowUtc()).and()

View file

@ -65,7 +65,7 @@ public class ContactTransferRequestFlowTest
runFlowAssertResponse(readFile(expectedXmlFilename));
// Transfer should have been requested. Verify correct fields were set.
contact = reloadResourceByUniqueId();
contact = reloadResourceByForeignKey();
assertAboutContacts().that(contact)
.hasTransferStatus(TransferStatus.PENDING).and()
.hasTransferGainingClientId("NewRegistrar").and()

View file

@ -53,7 +53,7 @@ public class ContactUpdateFlowTest
assertTransactionalFlow(true);
runFlowAssertResponse(readFile("contact_update_response.xml"));
// Check that the contact was updated. This value came from the xml.
assertAboutContacts().that(reloadResourceByUniqueId())
assertAboutContacts().that(reloadResourceByForeignKey())
.hasAuthInfoPwd("2fooBAR").and()
.hasOnlyOneHistoryEntryWhich()
.hasNoXml();
@ -79,7 +79,7 @@ public class ContactUpdateFlowTest
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build());
doSuccessfulTest();
assertAboutContacts().that(reloadResourceByUniqueId())
assertAboutContacts().that(reloadResourceByForeignKey())
.doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED);
}
@ -107,7 +107,7 @@ public class ContactUpdateFlowTest
.hasInternationalizedPostalInfo(null);
runFlowAssertResponse(readFile("contact_update_response.xml"));
assertAboutContacts().that(reloadResourceByUniqueId())
assertAboutContacts().that(reloadResourceByForeignKey())
.hasLocalizedPostalInfo(null).and()
.hasNonNullInternationalizedPostalInfo();
}
@ -133,7 +133,7 @@ public class ContactUpdateFlowTest
clock.advanceOneMilli();
// The test xml updates the address of the postal info and should leave the name untouched.
runFlowAssertResponse(readFile("contact_update_response.xml"));
assertAboutContacts().that(reloadResourceByUniqueId()).hasLocalizedPostalInfo(
assertAboutContacts().that(reloadResourceByForeignKey()).hasLocalizedPostalInfo(
new PostalInfo.Builder()
.setType(Type.LOCALIZED)
.setName("A. Person")
@ -213,7 +213,7 @@ public class ContactUpdateFlowTest
CommitMode.LIVE,
UserPrivileges.SUPERUSER,
readFile("contact_update_response.xml"));
assertAboutContacts().that(reloadResourceByUniqueId())
assertAboutContacts().that(reloadResourceByForeignKey())
.hasStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED).and()
.hasStatusValue(StatusValue.SERVER_DELETE_PROHIBITED);
}

View file

@ -16,7 +16,7 @@ package google.registry.flows.domain;
import static com.google.common.io.BaseEncoding.base16;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.assertBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld;
@ -132,7 +132,7 @@ public class DomainAllocateFlowTest
UserPrivileges.SUPERUSER,
readFile("domain_allocate_response.xml"));
// Check that the domain was created and persisted with a history entry.
DomainResource domain = reloadResourceByUniqueId();
DomainResource domain = reloadResourceByForeignKey();
assertAboutDomains().that(domain)
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.DOMAIN_ALLOCATE);
@ -142,8 +142,7 @@ public class DomainAllocateFlowTest
boolean sunrushAddGracePeriod = (nameservers == 0);
// The application should be marked as allocated, with a new history entry.
DomainApplication application =
loadByUniqueId(DomainApplication.class, applicationId, clock.nowUtc());
DomainApplication application = loadDomainApplication(applicationId, clock.nowUtc());
assertAboutApplications().that(application)
.hasApplicationStatus(ApplicationStatus.ALLOCATED).and()
.hasHistoryEntryAtIndex(1)
@ -284,7 +283,7 @@ public class DomainAllocateFlowTest
setupDomainApplication("tld", TldState.QUIET_PERIOD);
setEppInput("domain_allocate_dsdata.xml");
doSuccessfulTest(2);
assertAboutDomains().that(reloadResourceByUniqueId())
assertAboutDomains().that(reloadResourceByForeignKey())
.hasExactlyDsData(DelegationSignerData.create(
12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC")));
}
@ -295,7 +294,7 @@ public class DomainAllocateFlowTest
setEppInput("domain_allocate_dsdata_8_records.xml");
doSuccessfulTest(2);
assertThat(getOnlyGlobalResource(DomainResource.class)).isNotNull();
assertThat(reloadResourceByUniqueId().getDsData()).hasSize(8);
assertThat(reloadResourceByForeignKey().getDsData()).hasSize(8);
}
@Test
@ -326,7 +325,7 @@ public class DomainAllocateFlowTest
String expectedCsv = String.format(
"%s,example-one.tld,370d0b7c9223372036854775807,1,"
+ "2010-09-16T10:00:00.000Z,2010-07-16T09:00:00.000Z,2010-08-16T10:00:00.000Z",
reloadResourceByUniqueId().getRepoId());
reloadResourceByForeignKey().getRepoId());
assertTasksEnqueued(
"lordn-claims", new TaskMatcher().payload(expectedCsv).tag("tld"));
}
@ -339,7 +338,7 @@ public class DomainAllocateFlowTest
String expectedCsv = String.format(
"%s,example-one.tld,370d0b7c9223372036854775807,1,"
+ "2011-08-17T09:00:00.000Z,2010-07-16T09:00:00.000Z,2010-08-16T10:00:00.000Z",
reloadResourceByUniqueId().getRepoId());
reloadResourceByForeignKey().getRepoId());
assertTasksEnqueued("lordn-claims", new TaskMatcher().payload(expectedCsv).tag("tld"));
}

View file

@ -15,7 +15,7 @@
package google.registry.flows.domain;
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.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainApplication;
@ -65,7 +65,7 @@ public class DomainApplicationDeleteFlowTest
clock.advanceOneMilli();
runFlowAssertResponse(readFile("domain_delete_response.xml"));
// Check that the domain is fully deleted.
assertThat(reloadResourceByUniqueId()).isNull();
assertThat(reloadDomainApplication()).isNull();
assertNoBillingEvents();
}
@ -86,15 +86,15 @@ public class DomainApplicationDeleteFlowTest
.setRepoId("1-TLD")
.setRegistrant(
Key.create(
loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc())))
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())))
.setNameservers(ImmutableSet.of(
Key.create(
loadByUniqueId(HostResource.class, "ns1.example.net", clock.nowUtc()))))
loadByForeignKey(HostResource.class, "ns1.example.net", clock.nowUtc()))))
.build());
doSuccessfulTest();
for (EppResource resource : new EppResource[]{
loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc()),
loadByUniqueId(HostResource.class, "ns1.example.net", clock.nowUtc()) }) {
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()),
loadByForeignKey(HostResource.class, "ns1.example.net", clock.nowUtc()) }) {
assertAboutEppResources().that(resource).doesNotHaveStatusValue(StatusValue.LINKED);
}
}

View file

@ -17,7 +17,7 @@ package google.registry.flows.domain;
import static com.google.common.collect.Sets.union;
import static com.google.common.io.BaseEncoding.base16;
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.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.generateNewDomainRoid;
@ -107,7 +107,7 @@ public class DomainApplicationUpdateFlowTest
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)),
DesignatedContact.create(Type.ADMIN, Key.create(unusedContact))))
.setNameservers(ImmutableSet.of(Key.create(
loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
.build());
}
@ -124,7 +124,7 @@ public class DomainApplicationUpdateFlowTest
clock.advanceOneMilli();
runFlowAssertResponse(readFile("domain_update_response.xml"));
// Check that the application was updated. These values came from the xml.
DomainApplication application = reloadResourceByUniqueId();
DomainApplication application = reloadDomainApplication();
assertAboutApplications().that(application)
.hasStatusValue(StatusValue.CLIENT_HOLD).and()
.hasOnlyOneHistoryEntryWhich()
@ -168,7 +168,7 @@ public class DomainApplicationUpdateFlowTest
public void testSuccess_registrantMovedToTechContact() throws Exception {
setEppInput("domain_update_sunrise_registrant_to_tech.xml");
persistReferencedEntities();
ContactResource sh8013 = loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc());
ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc());
persistResource(
newApplicationBuilder().setRegistrant(Key.create(sh8013)).build());
clock.advanceOneMilli();
@ -179,7 +179,7 @@ public class DomainApplicationUpdateFlowTest
public void testSuccess_multipleReferencesToSameContactRemoved() throws Exception {
setEppInput("domain_update_sunrise_remove_multiple_contacts.xml");
persistReferencedEntities();
ContactResource sh8013 = loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc());
ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc());
Key<ContactResource> sh8013Key = Key.create(sh8013);
persistResource(newApplicationBuilder()
.setRegistrant(sh8013Key)
@ -199,7 +199,7 @@ public class DomainApplicationUpdateFlowTest
ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)).build());
clock.advanceOneMilli();
runFlow();
assertAboutApplications().that(reloadResourceByUniqueId())
assertAboutApplications().that(reloadDomainApplication())
.doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED);
}
@ -213,7 +213,7 @@ public class DomainApplicationUpdateFlowTest
assertTransactionalFlow(true);
clock.advanceOneMilli();
runFlowAssertResponse(readFile("domain_update_response.xml"));
assertAboutApplications().that(reloadResourceByUniqueId())
assertAboutApplications().that(reloadDomainApplication())
.hasExactlyDsData(expectedDsData).and()
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE);
@ -372,11 +372,11 @@ public class DomainApplicationUpdateFlowTest
ImmutableSet.Builder<Key<HostResource>> nameservers = new ImmutableSet.Builder<>();
for (int i = 1; i < 15; i++) {
if (i != 2) { // Skip 2 since that's the one that the tests will add.
nameservers.add(Key.create(loadByUniqueId(
nameservers.add(Key.create(loadByForeignKey(
HostResource.class, String.format("ns%d.example.tld", i), clock.nowUtc())));
}
}
persistResource(reloadResourceByUniqueId().asBuilder()
persistResource(reloadDomainApplication().asBuilder()
.setNameservers(nameservers.build())
.build());
}
@ -491,9 +491,9 @@ public class DomainApplicationUpdateFlowTest
persistNewApplication();
// Add a tech contact to the persisted entity, which should cause the flow to fail when it tries
// to add "mak21" as a second tech contact.
persistResource(reloadResourceByUniqueId().asBuilder().setContacts(ImmutableSet.of(
persistResource(reloadDomainApplication().asBuilder().setContacts(ImmutableSet.of(
DesignatedContact.create(Type.TECH, Key.create(
loadByUniqueId(ContactResource.class, "foo", clock.nowUtc()))))).build());
loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))).build());
runFlow();
}
@ -577,7 +577,7 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities();
persistResource(newApplicationBuilder()
.setNameservers(ImmutableSet.of(Key.create(
loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
.build());
runFlow();
}
@ -591,7 +591,7 @@ public class DomainApplicationUpdateFlowTest
.setContacts(ImmutableSet.of(DesignatedContact.create(
Type.TECH,
Key.create(
loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc())))))
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())))))
.build());
runFlow();
}

View file

@ -165,7 +165,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
}
private void assertSuccessfulCreate(String domainTld, boolean isAnchorTenant) throws Exception {
DomainResource domain = reloadResourceByUniqueId();
DomainResource domain = reloadResourceByForeignKey();
// Calculate the total cost.
Money cost = getPricesForDomainName(getUniqueIdFromCommand(), clock.nowUtc()).isPremium()
@ -255,21 +255,21 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
private void assertNoLordn() throws Exception {
// TODO(b/26161326): Assert tasks NOT enqueued.
assertAboutDomains().that(reloadResourceByUniqueId())
assertAboutDomains().that(reloadResourceByForeignKey())
.hasSmdId(null).and()
.hasLaunchNotice(null);
}
private void assertSunriseLordn() throws Exception {
// TODO(b/26161326): Assert tasks enqueued.
assertAboutDomains().that(reloadResourceByUniqueId())
assertAboutDomains().that(reloadResourceByForeignKey())
.hasSmdId("0000001761376042759136-65535").and()
.hasLaunchNotice(null);
}
private void assertClaimsLordn() throws Exception {
// TODO(b/26161326): Assert tasks enqueued.
assertAboutDomains().that(reloadResourceByUniqueId())
assertAboutDomains().that(reloadResourceByForeignKey())
.hasSmdId(null).and()
.hasLaunchNotice(LaunchNotice.create(
"370d0b7c9223372036854775807",
@ -479,7 +479,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
setEppInput("domain_create_metadata.xml");
persistContactsAndHosts();
doSuccessfulTest();
assertAboutDomains().that(reloadResourceByUniqueId())
assertAboutDomains().that(reloadResourceByForeignKey())
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.DOMAIN_CREATE).and()
.hasMetadataReason("domain-create-test").and()
@ -545,7 +545,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
setEppInput("domain_create_dsdata_no_maxsiglife.xml");
persistContactsAndHosts("tld"); // For some reason this sample uses "tld".
doSuccessfulTest("tld");
assertAboutDomains().that(reloadResourceByUniqueId()).hasExactlyDsData(
assertAboutDomains().that(reloadResourceByForeignKey()).hasExactlyDsData(
DelegationSignerData.create(12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC")));
}
@ -554,7 +554,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
setEppInput("domain_create_dsdata_8_records.xml");
persistContactsAndHosts("tld"); // For some reason this sample uses "tld".
doSuccessfulTest("tld");
assertAboutDomains().that(reloadResourceByUniqueId()).hasNumDsData(8);
assertAboutDomains().that(reloadResourceByForeignKey()).hasNumDsData(8);
}
@Test
@ -581,7 +581,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistContactsAndHosts();
runFlowAssertResponse(readFile("domain_create_response.xml"),
"epp.response.resData.creData.exDate"); // Ignore expiration date; we verify it below
assertAboutDomains().that(reloadResourceByUniqueId())
assertAboutDomains().that(reloadResourceByForeignKey())
.hasRegistrationExpirationTime(clock.nowUtc().plusYears(1));
assertDnsTasksEnqueued("example.tld");
}

View file

@ -16,7 +16,7 @@ package google.registry.flows.domain;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.domain.DomainTransferFlowTestCase.persistWithPendingTransfer;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.assertBillingEvents;
import static google.registry.testing.DatastoreHelper.createTlds;
@ -255,7 +255,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
clock.advanceOneMilli();
runFlowAssertResponse(readFile(responseFilename, substitutions));
// Check that the domain is fully deleted.
assertThat(reloadResourceByUniqueId()).isNull();
assertThat(reloadResourceByForeignKey()).isNull();
// The add grace period is for a billable action, so it should trigger a cancellation.
assertAutorenewClosedAndCancellationCreatedFor(
graceBillingEvent,
@ -313,7 +313,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
assertPollMessages(createAutorenewPollMessage("TheRegistrar").build());
clock.advanceOneMilli();
runFlowAssertResponse(readFile(responseFilename, substitutions));
DomainResource resource = reloadResourceByUniqueId();
DomainResource resource = reloadResourceByForeignKey();
// Check that the domain is in the pending delete state.
assertAboutDomains().that(resource)
.hasStatusValue(StatusValue.PENDING_DELETE).and()
@ -375,14 +375,14 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
// Modify the autorenew poll message so that it has unacked messages in the past. This should
// prevent it from being deleted when the domain is deleted.
persistResource(
ofy().load().key(reloadResourceByUniqueId().getAutorenewPollMessage()).now().asBuilder()
ofy().load().key(reloadResourceByForeignKey().getAutorenewPollMessage()).now().asBuilder()
.setEventTime(A_MONTH_FROM_NOW.minusYears(3))
.build());
clock.advanceOneMilli();
runFlowAssertResponse(readFile("domain_delete_response_pending.xml"));
// There should now be two poll messages; one for the delete of the domain (in the future), and
// another for the unacked autorenew messages.
DateTime deletionTime = reloadResourceByUniqueId().getDeletionTime();
DateTime deletionTime = reloadResourceByForeignKey().getDeletionTime();
assertThat(getPollMessages("TheRegistrar", deletionTime.minusMinutes(1)))
.hasSize(1);
assertThat(getPollMessages("TheRegistrar", deletionTime)).hasSize(2);
@ -482,10 +482,10 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
setupSuccessfulTest();
// Modify the domain we are testing to include a pending transfer.
TransferData oldTransferData =
persistWithPendingTransfer(reloadResourceByUniqueId()).getTransferData();
persistWithPendingTransfer(reloadResourceByForeignKey()).getTransferData();
clock.advanceOneMilli();
runFlowAssertResponse(readFile("domain_delete_response_pending.xml"));
DomainResource domain = reloadResourceByUniqueId();
DomainResource domain = reloadResourceByForeignKey();
// Check that the domain is in the pending delete state.
// The PENDING_TRANSFER status should be gone.
assertAboutDomains().that(domain)
@ -554,17 +554,20 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
setupGracePeriods(GracePeriod.forBillingEvent(GracePeriodStatus.ADD, graceBillingEvent));
// Add a nameserver.
HostResource host = persistResource(newHostResource("ns1.example.tld"));
persistResource(loadByUniqueId(
persistResource(loadByForeignKey(
DomainResource.class, getUniqueIdFromCommand(), clock.nowUtc())
.asBuilder()
.setNameservers(ImmutableSet.of(Key.create(host)))
.build());
// Persist another domain that's already been deleted and references this contact and host.
persistResource(newDomainResource("example1.tld").asBuilder()
.setRegistrant(Key.create(loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc())))
.setNameservers(ImmutableSet.of(Key.create(host)))
.setDeletionTime(START_OF_TIME)
.build());
persistResource(
newDomainResource("example1.tld")
.asBuilder()
.setRegistrant(
Key.create(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())))
.setNameservers(ImmutableSet.of(Key.create(host)))
.setDeletionTime(START_OF_TIME)
.build());
clock.advanceOneMilli();
runFlowAssertResponse(readFile("domain_delete_response.xml"));
assertDnsTasksEnqueued("example.tld");
@ -578,7 +581,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
setupSuccessfulTest();
persistResource(
newHostResource("ns1." + getUniqueIdFromCommand()).asBuilder()
.setSuperordinateDomain(Key.create(reloadResourceByUniqueId()))
.setSuperordinateDomain(Key.create(reloadResourceByForeignKey()))
.setDeletionTime(clock.nowUtc().minusDays(1))
.build());
clock.advanceOneMilli();
@ -610,7 +613,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
DomainResource domain = persistActiveDomain(getUniqueIdFromCommand());
HostResource subordinateHost = persistResource(
newHostResource("ns1." + getUniqueIdFromCommand()).asBuilder()
.setSuperordinateDomain(Key.create(reloadResourceByUniqueId()))
.setSuperordinateDomain(Key.create(reloadResourceByForeignKey()))
.build());
domain = persistResource(domain.asBuilder()
.addSubordinateHost(subordinateHost.getFullyQualifiedHostName())
@ -681,7 +684,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
setupSuccessfulTest();
clock.advanceOneMilli();
runFlow();
assertAboutDomains().that(reloadResourceByUniqueId())
assertAboutDomains().that(reloadResourceByForeignKey())
.hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.DOMAIN_CREATE,
HistoryEntry.Type.DOMAIN_DELETE);

View file

@ -135,10 +135,10 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
int renewalYears,
Map<String, String> substitutions) throws Exception {
assertTransactionalFlow(true);
DateTime currentExpiration = reloadResourceByUniqueId().getRegistrationExpirationTime();
DateTime currentExpiration = reloadResourceByForeignKey().getRegistrationExpirationTime();
DateTime newExpiration = currentExpiration.plusYears(renewalYears);
runFlowAssertResponse(readFile(responseFilename, substitutions));
DomainResource domain = reloadResourceByUniqueId();
DomainResource domain = reloadResourceByForeignKey();
HistoryEntry historyEntryDomainRenew =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RENEW);
assertThat(ofy().load().key(domain.getAutorenewBillingEvent()).now().getEventTime())
@ -351,12 +351,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
persistDomain();
// Modify the autorenew poll message so that it has an undelivered message in the past.
persistResource(
ofy().load().key(reloadResourceByUniqueId().getAutorenewPollMessage()).now().asBuilder()
ofy().load().key(reloadResourceByForeignKey().getAutorenewPollMessage()).now().asBuilder()
.setEventTime(expirationTime.minusYears(1))
.build());
runFlowAssertResponse(readFile("domain_renew_response.xml"));
HistoryEntry historyEntryDomainRenew =
getOnlyHistoryEntryOfType(reloadResourceByUniqueId(), HistoryEntry.Type.DOMAIN_RENEW);
getOnlyHistoryEntryOfType(reloadResourceByForeignKey(), HistoryEntry.Type.DOMAIN_RENEW);
assertPollMessages(
new PollMessage.Autorenew.Builder()
.setTargetId(getUniqueIdFromCommand())
@ -365,12 +365,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setAutorenewEndTime(clock.nowUtc())
.setMsg("Domain was auto-renewed.")
.setParent(getOnlyHistoryEntryOfType(
reloadResourceByUniqueId(), HistoryEntry.Type.DOMAIN_CREATE))
reloadResourceByForeignKey(), HistoryEntry.Type.DOMAIN_CREATE))
.build(),
new PollMessage.Autorenew.Builder()
.setTargetId(getUniqueIdFromCommand())
.setClientId("TheRegistrar")
.setEventTime(reloadResourceByUniqueId().getRegistrationExpirationTime())
.setEventTime(reloadResourceByForeignKey().getRegistrationExpirationTime())
.setAutorenewEndTime(END_OF_TIME)
.setMsg("Domain was auto-renewed.")
.setParent(historyEntryDomainRenew)
@ -529,7 +529,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
public void testFailure_pendingTransfer() throws Exception {
thrown.expect(DomainHasPendingTransferException.class);
persistDomain();
persistWithPendingTransfer(reloadResourceByUniqueId()
persistWithPendingTransfer(reloadResourceByForeignKey()
.asBuilder()
.setRegistrationExpirationTime(DateTime.parse("2001-09-08T22:00:00.0Z"))
.build());
@ -568,7 +568,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
thrown.expect(IncorrectCurrentExpirationDateException.class);
persistDomain();
// Note expiration time is off by one day.
persistResource(reloadResourceByUniqueId().asBuilder()
persistResource(reloadResourceByForeignKey().asBuilder()
.setRegistrationExpirationTime(DateTime.parse("2000-04-04T22:00:00.0Z"))
.build());
runFlow();

View file

@ -129,7 +129,7 @@ public class DomainRestoreRequestFlowTest extends
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1)))
.hasSize(1);
runFlowAssertResponse(readFile("domain_update_response.xml"));
DomainResource domain = reloadResourceByUniqueId();
DomainResource domain = reloadResourceByForeignKey();
HistoryEntry historyEntryDomainRestore =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE);
assertThat(ofy().load().key(domain.getAutorenewBillingEvent()).now().getEventTime())

View file

@ -16,7 +16,7 @@ package google.registry.flows.domain;
import static com.google.common.collect.Iterables.getOnlyElement;
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.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.assertBillingEventsForResource;
import static google.registry.testing.DatastoreHelper.createTld;
@ -141,7 +141,7 @@ public class DomainTransferApproveFlowTest
assertTransactionalFlow(true);
runFlowAssertResponse(readFile(expectedXmlFilename));
// Transfer should have succeeded. Verify correct fields were set.
domain = reloadResourceByUniqueId();
domain = reloadResourceByForeignKey();
assertAboutDomains().that(domain).hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.DOMAIN_CREATE,
HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST,
@ -280,7 +280,7 @@ public class DomainTransferApproveFlowTest
@Test
public void testSuccess_lastTransferTime_reflectedOnSubordinateHost() throws Exception {
domain = reloadResourceByUniqueId();
domain = reloadResourceByForeignKey();
// Set an older last transfer time on the subordinate host.
subordinateHost = persistResource(
subordinateHost.asBuilder()
@ -288,7 +288,7 @@ public class DomainTransferApproveFlowTest
.build());
doSuccessfulTest("tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml");
subordinateHost = loadByUniqueId(
subordinateHost = loadByForeignKey(
HostResource.class, subordinateHost.getFullyQualifiedHostName(), clock.nowUtc());
// Verify that the host's last transfer time is now that of when the superordinate domain was
// transferred.
@ -297,7 +297,7 @@ public class DomainTransferApproveFlowTest
@Test
public void testSuccess_lastTransferTime_overridesExistingOnSubordinateHost() throws Exception {
domain = reloadResourceByUniqueId();
domain = reloadResourceByForeignKey();
// Set an older last transfer time on the subordinate host.
subordinateHost = persistResource(
subordinateHost.asBuilder()
@ -306,7 +306,7 @@ public class DomainTransferApproveFlowTest
.build());
doSuccessfulTest("tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml");
subordinateHost = loadByUniqueId(
subordinateHost = loadByForeignKey(
HostResource.class, subordinateHost.getFullyQualifiedHostName(), clock.nowUtc());
// Verify that the host's last transfer time is now that of when the superordinate domain was
// transferred.
@ -316,7 +316,7 @@ public class DomainTransferApproveFlowTest
@Test
public void testSuccess_lastTransferTime_overridesExistingOnSubordinateHostWithNullTransferTime()
throws Exception {
domain = reloadResourceByUniqueId();
domain = reloadResourceByForeignKey();
// Set an older last transfer time on the subordinate host.
subordinateHost = persistResource(
subordinateHost.asBuilder()
@ -325,7 +325,7 @@ public class DomainTransferApproveFlowTest
.build());
doSuccessfulTest("tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml");
subordinateHost = loadByUniqueId(
subordinateHost = loadByForeignKey(
HostResource.class, subordinateHost.getFullyQualifiedHostName(), clock.nowUtc());
// Verify that the host's last transfer time is now that of when the superordinate domain was
// transferred.
@ -350,7 +350,7 @@ public class DomainTransferApproveFlowTest
@Test
public void testSuccess_autorenewBeforeTransfer() throws Exception {
DomainResource domain = reloadResourceByUniqueId();
DomainResource domain = reloadResourceByForeignKey();
DateTime oldExpirationTime = clock.nowUtc().minusDays(1);
persistResource(domain.asBuilder()
.setRegistrationExpirationTime(oldExpirationTime)

View file

@ -107,7 +107,7 @@ public class DomainTransferCancelFlowTest
runFlowAssertResponse(readFile(expectedXmlFilename));
// Transfer should have been cancelled. Verify correct fields were set.
domain = reloadResourceByUniqueId();
domain = reloadResourceByForeignKey();
assertTransferFailed(domain, TransferStatus.CLIENT_CANCELLED);
assertAboutDomains().that(domain)
.hasRegistrationExpirationTime(originalExpirationTime).and()

View file

@ -16,7 +16,7 @@ package google.registry.flows.domain;
import static com.google.common.base.Preconditions.checkState;
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.testing.DatastoreHelper.createBillingEventForTransfer;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.getOnlyHistoryEntryOfType;
@ -120,14 +120,15 @@ public class DomainTransferFlowTestCase<F extends Flow, R extends EppResource>
.setCreationClientId("TheRegistrar")
.setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z"))
.setRegistrationExpirationTime(REGISTRATION_EXPIRATION_TIME)
.setRegistrant(Key.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc())))
.setRegistrant(
Key.create(loadByForeignKey(ContactResource.class, "jd1234", clock.nowUtc())))
.setContacts(ImmutableSet.of(
DesignatedContact.create(
Type.ADMIN,
Key.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc()))),
Key.create(loadByForeignKey(ContactResource.class, "jd1234", clock.nowUtc()))),
DesignatedContact.create(
Type.TECH,
Key.create(loadByUniqueId(ContactResource.class, "jd1234", clock.nowUtc())))))
Key.create(loadByForeignKey(ContactResource.class, "jd1234", clock.nowUtc())))))
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("fooBAR")))
.addGracePeriod(GracePeriod.create(
GracePeriodStatus.ADD, clock.nowUtc().plusDays(10), "foo", null))

View file

@ -80,7 +80,7 @@ public class DomainTransferRejectFlowTest
ImmutableSet<GracePeriod> originalGracePeriods = domain.getGracePeriods();
runFlowAssertResponse(readFile(expectedXmlFilename));
// Transfer should have been rejected. Verify correct fields were set.
domain = reloadResourceByUniqueId();
domain = reloadResourceByForeignKey();
assertTransferFailed(domain, TransferStatus.CLIENT_REJECTED);
assertTransferFailed(
reloadResourceAndCloneAtTime(subordinateHost, clock.nowUtc()),

View file

@ -147,7 +147,7 @@ public class DomainTransferRequestFlowTest
assertTransactionalFlow(true);
runFlowAssertResponse(readFile(expectedXmlFilename, substitutions));
// Transfer should have been requested. Verify correct fields were set.
domain = reloadResourceByUniqueId();
domain = reloadResourceByForeignKey();
final HistoryEntry historyEntryTransferRequest =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST);
int registrationYears = domain.getTransferData().getExtendedRegistrationYears();
@ -503,7 +503,7 @@ public class DomainTransferRequestFlowTest
@Test
public void testSuccess_autorenewBeforeAutomaticTransfer() throws Exception {
DomainResource oldResource = persistResource(reloadResourceByUniqueId().asBuilder()
DomainResource oldResource = persistResource(reloadResourceByForeignKey().asBuilder()
.setRegistrationExpirationTime(clock.nowUtc().plusDays(1).plus(1))
.build());
clock.advanceOneMilli();

View file

@ -17,7 +17,7 @@ package google.registry.flows.domain;
import static com.google.common.collect.Sets.union;
import static com.google.common.io.BaseEncoding.base16;
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.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.assertBillingEvents;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
@ -121,7 +121,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
private DomainResource persistDomain() throws Exception {
HostResource host = loadByUniqueId(HostResource.class, "ns1.example.foo", clock.nowUtc());
HostResource host = loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc());
DomainResource domain = persistResource(
newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setContacts(ImmutableSet.of(
@ -142,7 +142,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
assertTransactionalFlow(true);
runFlowAssertResponse(readFile("domain_update_response.xml"));
// Check that the domain was updated. These values came from the xml.
assertAboutDomains().that(reloadResourceByUniqueId())
assertAboutDomains().that(reloadResourceByForeignKey())
.hasStatusValue(StatusValue.CLIENT_HOLD).and()
.hasAuthInfoPwd("2BARfoo").and()
.hasOneHistoryEntryEachOfTypes(
@ -178,12 +178,12 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
CommitMode.LIVE, userPrivileges, readFile("domain_update_response.xml"));
// Verify that the domain now has the new nameserver and is in the add grace period.
DomainResource resource = reloadResourceByUniqueId();
DomainResource resource = reloadResourceByForeignKey();
HistoryEntry historyEntryDomainUpdate =
getOnlyHistoryEntryOfType(resource, HistoryEntry.Type.DOMAIN_UPDATE);
assertThat(resource.getNameservers()).containsExactly(
Key.create(
loadByUniqueId(HostResource.class, "ns2.example.foo", clock.nowUtc())));
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc())));
BillingEvent.OneTime regularAddBillingEvent = new BillingEvent.OneTime.Builder()
.setReason(Reason.CREATE)
.setTargetId("example.tld")
@ -236,7 +236,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
getSunrushAddBillingEvent(clock.nowUtc().plusDays(20)));
// Modify domain so it has no nameservers and is in the sunrush add grace period.
persistResource(
reloadResourceByUniqueId().asBuilder()
reloadResourceByForeignKey().asBuilder()
.setNameservers(null)
.addGracePeriod(GracePeriod.forBillingEvent(
GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent))
@ -260,7 +260,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
// that grace period only has a couple days left so that the resultant add grace period will get
// truncated.
persistResource(
reloadResourceByUniqueId().asBuilder()
reloadResourceByForeignKey().asBuilder()
.setNameservers(null)
.addGracePeriod(GracePeriod.forBillingEvent(
GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent))
@ -279,9 +279,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
// Modify domain so that it is in the sunrush add grace period, has nameservers, but has a
// serverHold on it.
persistResource(
reloadResourceByUniqueId().asBuilder()
reloadResourceByForeignKey().asBuilder()
.setNameservers(ImmutableSet.of(Key.create(
loadByUniqueId(HostResource.class, "ns2.example.foo", clock.nowUtc()))))
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()))))
.addGracePeriod(GracePeriod.forBillingEvent(
GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent))
.addStatusValue(StatusValue.SERVER_HOLD)
@ -303,9 +303,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
// Modify domain so that it is in the sunrush add grace period, has nameservers, but has a
// serverHold on it.
persistResource(
reloadResourceByUniqueId().asBuilder()
reloadResourceByForeignKey().asBuilder()
.setNameservers(ImmutableSet.of(Key.create(
loadByUniqueId(HostResource.class, "ns2.example.foo", clock.nowUtc()))))
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()))))
.addGracePeriod(GracePeriod.forBillingEvent(
GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent))
.addStatusValue(StatusValue.CLIENT_HOLD)
@ -328,7 +328,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
// Modify domain so it has no nameservers and is in the sunrush add grace period, but also has a
// server hold on it that will prevent the sunrush add grace period from being removed.
persistResource(
reloadResourceByUniqueId().asBuilder()
reloadResourceByForeignKey().asBuilder()
.setNameservers(null)
.addGracePeriod(GracePeriod.forBillingEvent(
GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent))
@ -339,7 +339,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
CommitMode.LIVE, UserPrivileges.NORMAL, readFile("domain_update_response.xml"));
// Verify that the domain is still in the sunrush add grace period.
assertGracePeriods(
reloadResourceByUniqueId().getGracePeriods(),
reloadResourceByForeignKey().getGracePeriods(),
ImmutableMap.of(
GracePeriod.create(
GracePeriodStatus.SUNRUSH_ADD, endOfGracePeriod, "TheRegistrar", null),
@ -350,12 +350,12 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
ImmutableSet.Builder<Key<HostResource>> nameservers = new ImmutableSet.Builder<>();
for (int i = 1; i < 15; i++) {
if (i != 2) { // Skip 2 since that's the one that the tests will add.
nameservers.add(Key.create(loadByUniqueId(
nameservers.add(Key.create(loadByForeignKey(
HostResource.class, String.format("ns%d.example.foo", i), clock.nowUtc())));
}
}
persistResource(
reloadResourceByUniqueId().asBuilder()
reloadResourceByForeignKey().asBuilder()
.setNameservers(nameservers.build())
.build());
clock.advanceOneMilli();
@ -392,7 +392,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
}
ImmutableList<DesignatedContact> contacts = contactsBuilder.build();
persistResource(
reloadResourceByUniqueId().asBuilder()
reloadResourceByForeignKey().asBuilder()
.setNameservers(nameservers.build())
.setContacts(ImmutableSet.copyOf(contacts.subList(0, 3)))
.setRegistrant(contacts.get(3).getContactKey())
@ -400,7 +400,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
clock.advanceOneMilli();
assertTransactionalFlow(true);
runFlowAssertResponse(readFile("domain_update_response.xml"));
DomainResource domain = reloadResourceByUniqueId();
DomainResource domain = reloadResourceByForeignKey();
assertAboutDomains().that(domain)
.hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.DOMAIN_CREATE,
@ -421,7 +421,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReferencedEntities();
persistDomain();
runFlow();
DomainResource domain = reloadResourceByUniqueId();
DomainResource domain = reloadResourceByForeignKey();
assertAboutDomains().that(domain)
.hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.DOMAIN_CREATE,
@ -462,16 +462,16 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.addSubordinateHost("ns1.example.tld")
.addSubordinateHost("ns2.example.tld")
.setNameservers(ImmutableSet.of(Key.create(
loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
.build());
clock.advanceOneMilli();
assertTransactionalFlow(true);
runFlowAssertResponse(readFile("domain_update_response.xml"));
domain = reloadResourceByUniqueId();
domain = reloadResourceByForeignKey();
assertThat(domain.getNameservers()).containsExactly(Key.create(addedHost));
assertThat(domain.getSubordinateHosts()).containsExactly("ns1.example.tld", "ns2.example.tld");
existingHost = loadByUniqueId(HostResource.class, "ns1.example.tld", clock.nowUtc());
addedHost = loadByUniqueId(HostResource.class, "ns2.example.tld", clock.nowUtc());
existingHost = loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc());
addedHost = loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc());
assertThat(existingHost.getSuperordinateDomain()).isEqualTo(Key.create(domain));
assertThat(addedHost.getSuperordinateDomain()).isEqualTo(Key.create(domain));
}
@ -480,7 +480,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
public void testSuccess_registrantMovedToTechContact() throws Exception {
setEppInput("domain_update_registrant_to_tech.xml");
persistReferencedEntities();
ContactResource sh8013 = loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc());
ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc());
persistResource(
newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setRegistrant(Key.create(sh8013))
@ -493,7 +493,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
public void testSuccess_multipleReferencesToSameContactRemoved() throws Exception {
setEppInput("domain_update_remove_multiple_contacts.xml");
persistReferencedEntities();
ContactResource sh8013 = loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc());
ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc());
Key<ContactResource> sh8013Key = Key.create(sh8013);
persistResource(
newDomainResource(getUniqueIdFromCommand()).asBuilder()
@ -516,7 +516,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.build());
clock.advanceOneMilli();
runFlow();
assertAboutDomains().that(reloadResourceByUniqueId())
assertAboutDomains().that(reloadResourceByForeignKey())
.doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED);
}
@ -533,7 +533,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
assertTransactionalFlow(true);
clock.advanceOneMilli();
runFlowAssertResponse(readFile("domain_update_response.xml"));
DomainResource resource = reloadResourceByUniqueId();
DomainResource resource = reloadResourceByForeignKey();
assertAboutDomains().that(resource)
.hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.DOMAIN_UPDATE);
@ -660,7 +660,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setEventTime(clock.nowUtc())
.setBillingTime(clock.nowUtc())
.setParent(getOnlyHistoryEntryOfType(
reloadResourceByUniqueId(), HistoryEntry.Type.DOMAIN_UPDATE))
reloadResourceByForeignKey(), HistoryEntry.Type.DOMAIN_UPDATE))
.build());
} else {
assertNoBillingEvents();
@ -742,7 +742,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
CommitMode.LIVE,
UserPrivileges.SUPERUSER,
readFile("domain_update_response.xml"));
assertAboutDomains().that(reloadResourceByUniqueId())
assertAboutDomains().that(reloadResourceByForeignKey())
.hasStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED).and()
.hasStatusValue(StatusValue.SERVER_HOLD);
}
@ -891,10 +891,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
// Add a tech contact to the persisted entity, which should cause the flow to fail when it tries
// to add "mak21" as a second tech contact.
persistResource(
reloadResourceByUniqueId().asBuilder()
reloadResourceByForeignKey().asBuilder()
.setContacts(ImmutableSet.of(
DesignatedContact.create(Type.TECH, Key.create(
loadByUniqueId(ContactResource.class, "foo", clock.nowUtc())))))
loadByForeignKey(ContactResource.class, "foo", clock.nowUtc())))))
.build());
runFlow();
}
@ -990,7 +990,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistResource(
newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setNameservers(ImmutableSet.of(Key.create(
loadByUniqueId(HostResource.class, "ns1.example.foo", clock.nowUtc()))))
loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()))))
.build());
runFlow();
}
@ -1005,7 +1005,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setContacts(ImmutableSet.of(DesignatedContact.create(
Type.TECH,
Key.create(
loadByUniqueId(ContactResource.class, "sh8013", clock.nowUtc())))))
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())))))
.build());
runFlow();
}
@ -1048,7 +1048,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistActiveHost("ns1.example.foo");
persistActiveHost("ns2.example.foo");
persistActiveContact("sh8013");
persistResource(loadByUniqueId(ContactResource.class, "mak21", clock.nowUtc()).asBuilder()
persistResource(loadByForeignKey(ContactResource.class, "mak21", clock.nowUtc()).asBuilder()
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
clock.advanceOneMilli();
@ -1066,7 +1066,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistActiveContact("mak21");
persistActiveContact("sh8013");
persistResource(
loadByUniqueId(HostResource.class, "ns2.example.foo", clock.nowUtc()).asBuilder()
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()).asBuilder()
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
clock.advanceOneMilli();
@ -1111,11 +1111,11 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns1.example.foo", "ns2.example.foo"))
.build());
assertThat(reloadResourceByUniqueId().getNameservers()).doesNotContain(
Key.create(loadByUniqueId(HostResource.class, "ns2.example.foo", clock.nowUtc())));
assertThat(reloadResourceByForeignKey().getNameservers()).doesNotContain(
Key.create(loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc())));
runFlow();
assertThat(reloadResourceByUniqueId().getNameservers()).contains(
Key.create(loadByUniqueId(HostResource.class, "ns2.example.foo", clock.nowUtc())));
assertThat(reloadResourceByForeignKey().getNameservers()).contains(
Key.create(loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc())));
}
@Test
@ -1130,7 +1130,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
.build());
runFlow();
assertThat(ofy().load().key(reloadResourceByUniqueId().getRegistrant()).now().getContactId())
assertThat(ofy().load().key(reloadResourceByForeignKey().getRegistrant()).now().getContactId())
.isEqualTo("sh8013");
}
@ -1152,21 +1152,21 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReferencedEntities();
persistDomain();
persistResource(
reloadResourceByUniqueId().asBuilder()
reloadResourceByForeignKey().asBuilder()
.addNameservers(ImmutableSet.of(Key.create(
loadByUniqueId(HostResource.class, "ns2.example.foo", clock.nowUtc()))))
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()))))
.build());
persistResource(
Registry.get("tld").asBuilder()
.setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns1.example.foo", "ns2.example.foo"))
.build());
assertThat(reloadResourceByUniqueId().getNameservers()).contains(
Key.create(loadByUniqueId(HostResource.class, "ns1.example.foo", clock.nowUtc())));
assertThat(reloadResourceByForeignKey().getNameservers()).contains(
Key.create(loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc())));
clock.advanceOneMilli();
runFlow();
assertThat(reloadResourceByUniqueId().getNameservers()).doesNotContain(
Key.create(loadByUniqueId(HostResource.class, "ns1.example.foo", clock.nowUtc())));
assertThat(reloadResourceByForeignKey().getNameservers()).doesNotContain(
Key.create(loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc())));
}
@Test

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);
}

View file

@ -17,7 +17,7 @@ package google.registry.mapreduce.inputs;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assert_;
import static google.registry.mapreduce.inputs.EppResourceInputs.createChildEntityInput;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.index.EppResourceIndexBucket.getBucketKey;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainResource;
@ -102,7 +102,7 @@ public class ChildEntityInputTest {
.build());
contactHistoryEntry = persistResource(
new HistoryEntry.Builder()
.setParent(loadByUniqueId(ContactResource.class, "contact1234", now))
.setParent(loadByForeignKey(ContactResource.class, "contact1234", now))
.setModificationTime(now)
.build());
oneTimeA = persistResource(

View file

@ -15,7 +15,7 @@
package google.registry.model.contact;
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.testing.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps;
import static google.registry.testing.DatastoreHelper.createTld;
@ -120,7 +120,7 @@ public class ContactResourceTest extends EntityTestCase {
@Test
public void testPersistence() throws Exception {
assertThat(
loadByUniqueId(ContactResource.class, contactResource.getForeignKey(), clock.nowUtc()))
loadByForeignKey(ContactResource.class, contactResource.getForeignKey(), clock.nowUtc()))
.isEqualTo(contactResource);
}

View file

@ -15,7 +15,7 @@
package google.registry.model.domain;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainApplication;
@ -111,10 +111,8 @@ public class DomainApplicationTest extends EntityTestCase {
@Test
public void testPersistence() throws Exception {
assertThat(
loadByUniqueId(
DomainApplication.class, domainApplication.getForeignKey(), clock.nowUtc()))
.isEqualTo(domainApplication);
assertThat(loadDomainApplication(domainApplication.getForeignKey(), clock.nowUtc()))
.isEqualTo(domainApplication);
}
@Test

View file

@ -18,7 +18,7 @@ import static com.google.appengine.tools.development.testing.LocalMemcacheServic
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.collect.Iterables.skip;
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.testing.DatastoreHelper.cloneAndSetAutoTimestamps;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainResource;
@ -157,7 +157,7 @@ public class DomainResourceTest extends EntityTestCase {
@Test
public void testPersistence() throws Exception {
assertThat(loadByUniqueId(DomainResource.class, domain.getForeignKey(), clock.nowUtc()))
assertThat(loadByForeignKey(DomainResource.class, domain.getForeignKey(), clock.nowUtc()))
.isEqualTo(domain);
}

View file

@ -15,7 +15,7 @@
package google.registry.model.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.testing.DatastoreHelper.cloneAndSetAutoTimestamps;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainResource;
@ -83,14 +83,15 @@ public class HostResourceTest extends EntityTestCase {
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.setStatusValues(ImmutableSet.of(StatusValue.OK))
.setSuperordinateDomain(
Key.create(loadByUniqueId(DomainResource.class, "example.com", clock.nowUtc())))
Key.create(
loadByForeignKey(DomainResource.class, "example.com", clock.nowUtc())))
.build());
persistResource(hostResource);
}
@Test
public void testPersistence() throws Exception {
assertThat(loadByUniqueId(
assertThat(loadByForeignKey(
HostResource.class, hostResource.getForeignKey(), clock.nowUtc()))
.isEqualTo(hostResource.cloneProjectedAtTime(clock.nowUtc()));
}
@ -125,9 +126,9 @@ public class HostResourceTest extends EntityTestCase {
public void testCurrentSponsorClientId_comesFromSuperordinateDomain() {
assertThat(hostResource.getCurrentSponsorClientId()).isNull();
HostResource projectedHost =
loadByUniqueId(HostResource.class, hostResource.getForeignKey(), clock.nowUtc());
loadByForeignKey(HostResource.class, hostResource.getForeignKey(), clock.nowUtc());
assertThat(projectedHost.getCurrentSponsorClientId())
.isEqualTo(loadByUniqueId(
.isEqualTo(loadByForeignKey(
DomainResource.class,
"example.com",
clock.nowUtc())
@ -196,7 +197,7 @@ public class HostResourceTest extends EntityTestCase {
@Nullable DateTime domainTransferTime,
@Nullable DateTime hostTransferTime,
@Nullable DateTime superordinateChangeTime) {
DomainResource domain = loadByUniqueId(
DomainResource domain = loadByForeignKey(
DomainResource.class, "example.com", clock.nowUtc());
persistResource(
domain.asBuilder().setTransferData(null).setLastTransferTime(domainTransferTime).build());
@ -256,7 +257,7 @@ public class HostResourceTest extends EntityTestCase {
@Test
public void testExpiredTransfer_subordinateHost() {
DomainResource domain = loadByUniqueId(
DomainResource domain = loadByForeignKey(
DomainResource.class, "example.com", clock.nowUtc());
persistResource(domain.asBuilder()
.setTransferData(domain.getTransferData().asBuilder()