Make loadByForeignKey() and related methods return Optional

This is safer and addresses a common source of confusion in the codebase because it's always explicit that the resource returned may not be present, whether because it's soft-deleted when projected to the given time or because it never existed in the first place.

In production code, the presence of the returned value is always checked. In test code, its presence is assumed using .get() where that is expected and convenient, as it not being present will throw an NPE that will cause the test to fail anyway.

Note that the roughly equivalent reloadResourceByForeignKey(), which is widely used in test code, is not having this same treatment applied to it. That is out of the scope of this CL, and has much smaller returns anyway because it's only used in tests (where the unexpected absence of a given resource would just cause the test to fail).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=225424002
This commit is contained in:
mcilwain 2018-12-13 13:17:30 -08:00 committed by jianglai
parent b573ec4969
commit 4491b7b909
52 changed files with 374 additions and 290 deletions

View file

@ -65,13 +65,14 @@ public final class RefreshDnsAction implements Runnable {
private <T extends EppResource & ForeignKeyedEppResource> private <T extends EppResource & ForeignKeyedEppResource>
T loadAndVerifyExistence(Class<T> clazz, String foreignKey) { T loadAndVerifyExistence(Class<T> clazz, String foreignKey) {
T resource = loadByForeignKey(clazz, foreignKey, clock.nowUtc()); return loadByForeignKey(clazz, foreignKey, clock.nowUtc())
if (resource == null) { .orElseThrow(
String typeName = clazz.getAnnotation(ExternalMessagingName.class).value(); () ->
throw new NotFoundException( new NotFoundException(
String.format("%s %s not found", typeName, domainOrHostName)); String.format(
} "%s %s not found",
return resource; clazz.getAnnotation(ExternalMessagingName.class).value(),
domainOrHostName)));
} }
private static void verifyHostIsSubordinate(HostResource host) { private static void verifyHostIsSubordinate(HostResource host) {

View file

@ -120,9 +120,9 @@ public class CloudDnsWriter extends BaseDnsWriter {
// Canonicalize name // Canonicalize name
String absoluteDomainName = getAbsoluteHostName(domainName); String absoluteDomainName = getAbsoluteHostName(domainName);
// Load the target domain. Note that it can be null if this domain was just deleted. // Load the target domain. Note that it can be absent if this domain was just deleted.
Optional<DomainResource> domainResource = Optional<DomainResource> domainResource =
Optional.ofNullable(loadByForeignKey(DomainResource.class, domainName, clock.nowUtc())); loadByForeignKey(DomainResource.class, domainName, clock.nowUtc());
// Return early if no DNS records should be published. // Return early if no DNS records should be published.
// desiredRecordsBuilder is populated with an empty set to indicate that all existing records // desiredRecordsBuilder is populated with an empty set to indicate that all existing records
@ -188,11 +188,10 @@ public class CloudDnsWriter extends BaseDnsWriter {
// Canonicalize name // Canonicalize name
String absoluteHostName = getAbsoluteHostName(hostName); String absoluteHostName = getAbsoluteHostName(hostName);
// Load the target host. Note that it can be null if this host was just deleted. // Load the target host. Note that it can be absent if this host was just deleted.
// desiredRecords is populated with an empty set to indicate that all existing records // desiredRecords is populated with an empty set to indicate that all existing records
// should be deleted. // should be deleted.
Optional<HostResource> host = Optional<HostResource> host = loadByForeignKey(HostResource.class, hostName, clock.nowUtc());
Optional.ofNullable(loadByForeignKey(HostResource.class, hostName, clock.nowUtc()));
// Return early if the host is deleted. // Return early if the host is deleted.
if (!host.isPresent()) { if (!host.isPresent()) {

View file

@ -14,6 +14,7 @@
package google.registry.dns.writer.dnsupdate; package google.registry.dns.writer.dnsupdate;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Verify.verify; import static com.google.common.base.Verify.verify;
import static com.google.common.collect.Sets.intersection; import static com.google.common.collect.Sets.intersection;
import static com.google.common.collect.Sets.union; import static com.google.common.collect.Sets.union;
@ -126,9 +127,12 @@ public class DnsUpdateWriter extends BaseDnsWriter {
* this domain refresh request * this domain refresh request
*/ */
private void publishDomain(String domainName, String requestingHostName) { private void publishDomain(String domainName, String requestingHostName) {
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, clock.nowUtc()); Optional<DomainResource> domainOptional =
loadByForeignKey(DomainResource.class, domainName, clock.nowUtc());
update.delete(toAbsoluteName(domainName), Type.ANY); update.delete(toAbsoluteName(domainName), Type.ANY);
if (domain != null) { // If the domain is now deleted, then don't update DNS for it.
if (domainOptional.isPresent()) {
DomainResource domain = domainOptional.get();
// As long as the domain exists, orphan glues should be cleaned. // As long as the domain exists, orphan glues should be cleaned.
deleteSubordinateHostAddressSet(domain, requestingHostName, update); deleteSubordinateHostAddressSet(domain, requestingHostName, update);
if (domain.shouldPublishToDns()) { if (domain.shouldPublishToDns()) {
@ -213,9 +217,10 @@ public class DnsUpdateWriter extends BaseDnsWriter {
for (String hostName : for (String hostName :
intersection( intersection(
domain.loadNameserverFullyQualifiedHostNames(), domain.getSubordinateHosts())) { domain.loadNameserverFullyQualifiedHostNames(), domain.getSubordinateHosts())) {
HostResource host = loadByForeignKey(HostResource.class, hostName, clock.nowUtc()); Optional<HostResource> host = loadByForeignKey(HostResource.class, hostName, clock.nowUtc());
update.add(makeAddressSet(host)); checkState(host.isPresent(), "Host %s cannot be loaded", hostName);
update.add(makeV6AddressSet(host)); update.add(makeAddressSet(host.get()));
update.add(makeV6AddressSet(host.get()));
} }
} }

View file

@ -292,11 +292,8 @@ public final class ResourceFlowUtils {
} }
public static <R extends EppResource> R verifyExistence( public static <R extends EppResource> R verifyExistence(
Class<R> clazz, String targetId, R resource) throws ResourceDoesNotExistException { Class<R> clazz, String targetId, Optional<R> resource) throws ResourceDoesNotExistException {
if (resource == null) { return resource.orElseThrow(() -> new ResourceDoesNotExistException(clazz, targetId));
throw new ResourceDoesNotExistException(clazz, targetId);
}
return resource;
} }
public static <R extends EppResource> void verifyResourceDoesNotExist( public static <R extends EppResource> void verifyResourceDoesNotExist(

View file

@ -224,10 +224,9 @@ public class DomainAllocateFlow implements TransactionalFlow {
private DomainApplication loadAndValidateApplication( private DomainApplication loadAndValidateApplication(
String applicationRoid, DateTime now) throws EppException { String applicationRoid, DateTime now) throws EppException {
DomainApplication application = loadDomainApplication(applicationRoid, now); DomainApplication application =
if (application == null) { loadDomainApplication(applicationRoid, now)
throw new MissingApplicationException(applicationRoid); .orElseThrow(() -> new MissingApplicationException(applicationRoid));
}
if (application.getApplicationStatus().isFinalStatus()) { if (application.getApplicationStatus().isFinalStatus()) {
throw new HasFinalStatusException(); throw new HasFinalStatusException();
} }

View file

@ -23,10 +23,10 @@ import static google.registry.flows.ResourceFlowUtils.verifyResourceOwnership;
import static google.registry.flows.domain.DomainFlowUtils.addSecDnsExtensionIfPresent; import static google.registry.flows.domain.DomainFlowUtils.addSecDnsExtensionIfPresent;
import static google.registry.flows.domain.DomainFlowUtils.loadForeignKeyedDesignatedContacts; import static google.registry.flows.domain.DomainFlowUtils.loadForeignKeyedDesignatedContacts;
import static google.registry.flows.domain.DomainFlowUtils.verifyApplicationDomainMatchesTargetId; import static google.registry.flows.domain.DomainFlowUtils.verifyApplicationDomainMatchesTargetId;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.googlecode.objectify.Key;
import google.registry.flows.EppException; import google.registry.flows.EppException;
import google.registry.flows.EppException.ParameterValuePolicyErrorException; import google.registry.flows.EppException.ParameterValuePolicyErrorException;
import google.registry.flows.EppException.RequiredParameterMissingException; import google.registry.flows.EppException.RequiredParameterMissingException;
@ -89,13 +89,10 @@ public final class DomainApplicationInfoFlow implements Flow {
throw new MissingApplicationIdException(); throw new MissingApplicationIdException();
} }
DomainApplication application = DomainApplication application =
ofy().load().key(Key.create(DomainApplication.class, applicationId)).now();
verifyExistence( verifyExistence(
DomainApplication.class, DomainApplication.class,
applicationId, applicationId,
application != null && clock.nowUtc().isBefore(application.getDeletionTime()) loadDomainApplication(applicationId, clock.nowUtc()));
? application
: null);
verifyApplicationDomainMatchesTargetId(application, targetId); verifyApplicationDomainMatchesTargetId(application, targetId);
verifyOptionalAuthInfo(authInfo, application); verifyOptionalAuthInfo(authInfo, application);
LaunchInfoExtension launchInfo = eppInput.getSingleExtension(LaunchInfoExtension.class).get(); LaunchInfoExtension launchInfo = eppInput.getSingleExtension(LaunchInfoExtension.class).get();

View file

@ -87,16 +87,15 @@ public class HostFlowUtils {
} }
// This is a subordinate host // This is a subordinate host
String domainName = String domainName =
hostName hostName.parts().stream()
.parts()
.stream()
.skip(hostName.parts().size() - (tld.get().parts().size() + 1)) .skip(hostName.parts().size() - (tld.get().parts().size() + 1))
.collect(joining(".")); .collect(joining("."));
DomainResource superordinateDomain = loadByForeignKey(DomainResource.class, domainName, now); Optional<DomainResource> superordinateDomain =
if (superordinateDomain == null || !isActive(superordinateDomain, now)) { loadByForeignKey(DomainResource.class, domainName, now);
if (!superordinateDomain.isPresent() || !isActive(superordinateDomain.get(), now)) {
throw new SuperordinateDomainDoesNotExistException(domainName); throw new SuperordinateDomainDoesNotExistException(domainName);
} }
return Optional.of(superordinateDomain); return superordinateDomain;
} }
/** Superordinate domain for this hostname does not exist. */ /** Superordinate domain for this hostname does not exist. */

View file

@ -76,7 +76,7 @@ public final class EppResourceUtils {
/** /**
* Loads the last created version of an {@link EppResource} from Datastore by foreign key. * Loads the last created version of an {@link EppResource} from Datastore by foreign key.
* *
* <p>Returns null if no resource with this foreign key was ever created, or if the most recently * <p>Returns empty if no resource with this foreign key was ever created, or if the most recently
* created resource was deleted before time "now". * created resource was deleted before time "now".
* *
* <p>Loading an {@link EppResource} by itself is not sufficient to know its current state since * <p>Loading an {@link EppResource} by itself is not sufficient to know its current state since
@ -92,10 +92,9 @@ public final class EppResourceUtils {
* @param foreignKey id to match * @param foreignKey id to match
* @param now the current logical time to project resources at * @param now the current logical time to project resources at
*/ */
@Nullable public static <T extends EppResource> Optional<T> loadByForeignKey(
public static <T extends EppResource> T loadByForeignKey(
Class<T> clazz, String foreignKey, DateTime now) { Class<T> clazz, String foreignKey, DateTime now) {
return loadByForeignKeyHelper(clazz, foreignKey, now, false).orElse(null); return loadByForeignKeyHelper(clazz, foreignKey, now, false);
} }
/** /**
@ -160,19 +159,19 @@ public final class EppResourceUtils {
} }
/** /**
* Returns the domain application with the given application id if it exists, or null if it does * Returns the domain application with the given application id if it exists, or absent if it does
* not or is soft-deleted as of the given time. * not or is soft-deleted as of the given time.
*/ */
@Nullable public static Optional<DomainApplication> loadDomainApplication(
public static DomainApplication loadDomainApplication(String applicationId, DateTime now) { String applicationId, DateTime now) {
DomainApplication application = DomainApplication application =
ofy().load().key(Key.create(DomainApplication.class, applicationId)).now(); ofy().load().key(Key.create(DomainApplication.class, applicationId)).now();
if (application == null || isAtOrAfter(now, application.getDeletionTime())) { if (application == null || isAtOrAfter(now, application.getDeletionTime())) {
return null; return Optional.empty();
} }
// Applications don't have any speculative changes that become effective later, so no need to // Applications don't have any speculative changes that become effective later, so no need to
// clone forward in time. // clone forward in time.
return application; return Optional.of(application);
} }
/** /**

View file

@ -21,6 +21,7 @@ import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet;
import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.union; import static com.google.common.collect.Sets.union;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.CollectionUtils.forceEmptyToNull;
import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy; import static google.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy;
@ -231,21 +232,38 @@ public abstract class DomainBase extends EppResource {
return thisCastToDerived(); return thisCastToDerived();
} }
public B setNameservers(ImmutableSet<Key<HostResource>> nameservers) { public B setNameservers(Key<HostResource> nameserver) {
getInstance().nsHosts = nameservers; getInstance().nsHosts = ImmutableSet.of(nameserver);
return thisCastToDerived(); return thisCastToDerived();
} }
public B setNameservers(ImmutableSet<Key<HostResource>> nameservers) {
getInstance().nsHosts = forceEmptyToNull(nameservers);
return thisCastToDerived();
}
public B addNameserver(Key<HostResource> nameserver) {
return addNameservers(ImmutableSet.of(nameserver));
}
public B addNameservers(ImmutableSet<Key<HostResource>> nameservers) { public B addNameservers(ImmutableSet<Key<HostResource>> nameservers) {
return setNameservers( return setNameservers(
ImmutableSet.copyOf(union(getInstance().getNameservers(), nameservers))); ImmutableSet.copyOf(union(getInstance().getNameservers(), nameservers)));
} }
public B removeNameserver(Key<HostResource> nameserver) {
return removeNameservers(ImmutableSet.of(nameserver));
}
public B removeNameservers(ImmutableSet<Key<HostResource>> nameservers) { public B removeNameservers(ImmutableSet<Key<HostResource>> nameservers) {
return setNameservers( return setNameservers(
ImmutableSet.copyOf(difference(getInstance().getNameservers(), nameservers))); ImmutableSet.copyOf(difference(getInstance().getNameservers(), nameservers)));
} }
public B setContacts(DesignatedContact contact) {
return setContacts(ImmutableSet.of(contact));
}
public B setContacts(ImmutableSet<DesignatedContact> contacts) { public B setContacts(ImmutableSet<DesignatedContact> contacts) {
checkArgument(contacts.stream().noneMatch(IS_REGISTRANT), "Registrant cannot be a contact"); checkArgument(contacts.stream().noneMatch(IS_REGISTRANT), "Registrant cannot be a contact");
// Replace the non-registrant contacts inside allContacts. // Replace the non-registrant contacts inside allContacts.

View file

@ -272,6 +272,18 @@ public abstract class RdapActionBase implements Runnable {
|| registrarParam.get().equals(eppResource.getPersistedCurrentSponsorClientId())); || registrarParam.get().equals(eppResource.getPersistedCurrentSponsorClientId()));
} }
/**
* Returns true if the EPP resource should be visible.
*
* <p>This is true iff:
* 1. The passed in resource exists and is not deleted (deleted ones will have been projected
* forward in time to empty),
* 2. The request did not specify a registrar to filter on, or the registrar matches.
*/
boolean shouldBeVisible(Optional<? extends EppResource> eppResource, DateTime now) {
return eppResource.isPresent() && shouldBeVisible(eppResource.get(), now);
}
/** /**
* Returns true if the registrar should be visible. * Returns true if the registrar should be visible.
* *

View file

@ -29,6 +29,7 @@ import google.registry.request.Action;
import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.BadRequestException;
import google.registry.request.HttpException.NotFoundException; import google.registry.request.HttpException.NotFoundException;
import google.registry.request.auth.Auth; import google.registry.request.auth.Auth;
import java.util.Optional;
import javax.inject.Inject; import javax.inject.Inject;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -74,14 +75,14 @@ public class RdapDomainAction extends RdapActionBase {
pathSearchString, getHumanReadableObjectTypeName(), e.getMessage())); pathSearchString, getHumanReadableObjectTypeName(), e.getMessage()));
} }
// The query string is not used; the RDAP syntax is /rdap/domain/mydomain.com. // The query string is not used; the RDAP syntax is /rdap/domain/mydomain.com.
DomainResource domainResource = Optional<DomainResource> domainResource =
loadByForeignKey( loadByForeignKey(
DomainResource.class, pathSearchString, shouldIncludeDeleted() ? START_OF_TIME : now); DomainResource.class, pathSearchString, shouldIncludeDeleted() ? START_OF_TIME : now);
if ((domainResource == null) || !shouldBeVisible(domainResource, now)) { if (!shouldBeVisible(domainResource, now)) {
throw new NotFoundException(pathSearchString + " not found"); throw new NotFoundException(pathSearchString + " not found");
} }
return rdapJsonFormatter.makeRdapJsonForDomain( return rdapJsonFormatter.makeRdapJsonForDomain(
domainResource, domainResource.get(),
true, true,
fullServletPath, fullServletPath,
rdapWhoisServer, rdapWhoisServer,

View file

@ -216,13 +216,13 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
*/ */
private RdapSearchResults searchByDomainNameWithoutWildcard( private RdapSearchResults searchByDomainNameWithoutWildcard(
final RdapSearchPattern partialStringQuery, final DateTime now) { final RdapSearchPattern partialStringQuery, final DateTime now) {
DomainResource domainResource = Optional<DomainResource> domainResource =
loadByForeignKey(DomainResource.class, partialStringQuery.getInitialString(), now); loadByForeignKey(DomainResource.class, partialStringQuery.getInitialString(), now);
ImmutableList<DomainResource> results = return makeSearchResults(
((domainResource == null) || !shouldBeVisible(domainResource, now)) shouldBeVisible(domainResource, now)
? ImmutableList.of() ? ImmutableList.of(domainResource.get())
: ImmutableList.of(domainResource); : ImmutableList.of(),
return makeSearchResults(results, now); now);
} }
/** Searches for domains by domain name with an initial string, wildcard and possible suffix. */ /** Searches for domains by domain name with an initial string, wildcard and possible suffix. */
@ -343,15 +343,15 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
// the key. // the key.
Optional<String> desiredRegistrar = getDesiredRegistrar(); Optional<String> desiredRegistrar = getDesiredRegistrar();
if (desiredRegistrar.isPresent()) { if (desiredRegistrar.isPresent()) {
HostResource host = Optional<HostResource> host =
loadByForeignKey( loadByForeignKey(
HostResource.class, HostResource.class,
partialStringQuery.getInitialString(), partialStringQuery.getInitialString(),
shouldIncludeDeleted() ? START_OF_TIME : now); shouldIncludeDeleted() ? START_OF_TIME : now);
return ((host == null) return (!host.isPresent()
|| !desiredRegistrar.get().equals(host.getPersistedCurrentSponsorClientId())) || !desiredRegistrar.get().equals(host.get().getPersistedCurrentSponsorClientId()))
? ImmutableList.of() ? ImmutableList.of()
: ImmutableList.of(Key.create(host)); : ImmutableList.of(Key.create(host.get()));
} else { } else {
Key<HostResource> hostKey = Key<HostResource> hostKey =
loadAndGetKey( loadAndGetKey(
@ -372,13 +372,12 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
loadByForeignKey( loadByForeignKey(
DomainResource.class, DomainResource.class,
partialStringQuery.getSuffix(), partialStringQuery.getSuffix(),
shouldIncludeDeleted() ? START_OF_TIME : now); shouldIncludeDeleted() ? START_OF_TIME : now)
if (domainResource == null) { .orElseThrow(
// Don't allow wildcards with suffixes which are not domains we manage. That would risk a () ->
// table scan in some easily foreseeable cases. new UnprocessableEntityException(
throw new UnprocessableEntityException( "A suffix in a lookup by nameserver name "
"A suffix in a lookup by nameserver name must be a domain defined in the system"); + "must be a domain defined in the system"));
}
Optional<String> desiredRegistrar = getDesiredRegistrar(); Optional<String> desiredRegistrar = getDesiredRegistrar();
ImmutableList.Builder<Key<HostResource>> builder = new ImmutableList.Builder<>(); ImmutableList.Builder<Key<HostResource>> builder = new ImmutableList.Builder<>();
for (String fqhn : ImmutableSortedSet.copyOf(domainResource.getSubordinateHosts())) { for (String fqhn : ImmutableSortedSet.copyOf(domainResource.getSubordinateHosts())) {
@ -386,12 +385,12 @@ public class RdapDomainSearchAction extends RdapSearchActionBase {
// then the query ns.exam*.example.com would match against nameserver ns.example.com. // then the query ns.exam*.example.com would match against nameserver ns.example.com.
if (partialStringQuery.matches(fqhn)) { if (partialStringQuery.matches(fqhn)) {
if (desiredRegistrar.isPresent()) { if (desiredRegistrar.isPresent()) {
HostResource host = Optional<HostResource> host =
loadByForeignKey( loadByForeignKey(
HostResource.class, fqhn, shouldIncludeDeleted() ? START_OF_TIME : now); HostResource.class, fqhn, shouldIncludeDeleted() ? START_OF_TIME : now);
if ((host != null) if (host.isPresent()
&& desiredRegistrar.get().equals(host.getPersistedCurrentSponsorClientId())) { && desiredRegistrar.get().equals(host.get().getPersistedCurrentSponsorClientId())) {
builder.add(Key.create(host)); builder.add(Key.create(host.get()));
} }
} else { } else {
Key<HostResource> hostKey = Key<HostResource> hostKey =

View file

@ -29,6 +29,7 @@ import google.registry.request.Action;
import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.BadRequestException;
import google.registry.request.HttpException.NotFoundException; import google.registry.request.HttpException.NotFoundException;
import google.registry.request.auth.Auth; import google.registry.request.auth.Auth;
import java.util.Optional;
import javax.inject.Inject; import javax.inject.Inject;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -76,13 +77,13 @@ public class RdapNameserverAction extends RdapActionBase {
} }
// If there are no undeleted nameservers with the given name, the foreign key should point to // If there are no undeleted nameservers with the given name, the foreign key should point to
// the most recently deleted one. // the most recently deleted one.
HostResource hostResource = Optional<HostResource> hostResource =
loadByForeignKey( loadByForeignKey(
HostResource.class, pathSearchString, shouldIncludeDeleted() ? START_OF_TIME : now); HostResource.class, pathSearchString, shouldIncludeDeleted() ? START_OF_TIME : now);
if ((hostResource == null) || !shouldBeVisible(hostResource, now)) { if (!shouldBeVisible(hostResource, now)) {
throw new NotFoundException(pathSearchString + " not found"); throw new NotFoundException(pathSearchString + " not found");
} }
return rdapJsonFormatter.makeRdapJsonForHost( return rdapJsonFormatter.makeRdapJsonForHost(
hostResource, true, fullServletPath, rdapWhoisServer, now, OutputDataType.FULL); hostResource.get(), true, fullServletPath, rdapWhoisServer, now, OutputDataType.FULL);
} }
} }

View file

@ -183,9 +183,9 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
*/ */
private RdapSearchResults searchByNameUsingForeignKey( private RdapSearchResults searchByNameUsingForeignKey(
final RdapSearchPattern partialStringQuery, final DateTime now) { final RdapSearchPattern partialStringQuery, final DateTime now) {
HostResource hostResource = Optional<HostResource> hostResource =
loadByForeignKey(HostResource.class, partialStringQuery.getInitialString(), now); loadByForeignKey(HostResource.class, partialStringQuery.getInitialString(), now);
if ((hostResource == null) || !shouldBeVisible(hostResource, now)) { if (!shouldBeVisible(hostResource, now)) {
metricInformationBuilder.setNumHostsRetrieved(0); metricInformationBuilder.setNumHostsRetrieved(0);
throw new NotFoundException("No nameservers found"); throw new NotFoundException("No nameservers found");
} }
@ -193,15 +193,20 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
return RdapSearchResults.create( return RdapSearchResults.create(
ImmutableList.of( ImmutableList.of(
rdapJsonFormatter.makeRdapJsonForHost( rdapJsonFormatter.makeRdapJsonForHost(
hostResource, false, fullServletPath, rdapWhoisServer, now, OutputDataType.FULL))); hostResource.get(),
false,
fullServletPath,
rdapWhoisServer,
now,
OutputDataType.FULL)));
} }
/** Searches for nameservers by name using the superordinate domain as a suffix. */ /** Searches for nameservers by name using the superordinate domain as a suffix. */
private RdapSearchResults searchByNameUsingSuperordinateDomain( private RdapSearchResults searchByNameUsingSuperordinateDomain(
final RdapSearchPattern partialStringQuery, final DateTime now) { final RdapSearchPattern partialStringQuery, final DateTime now) {
DomainResource domainResource = Optional<DomainResource> domainResource =
loadByForeignKey(DomainResource.class, partialStringQuery.getSuffix(), now); loadByForeignKey(DomainResource.class, partialStringQuery.getSuffix(), now);
if (domainResource == null) { if (!domainResource.isPresent()) {
// Don't allow wildcards with suffixes which are not domains we manage. That would risk a // Don't allow wildcards with suffixes which are not domains we manage. That would risk a
// table scan in many easily foreseeable cases. The user might ask for ns*.zombo.com, // table scan in many easily foreseeable cases. The user might ask for ns*.zombo.com,
// forcing us to query for all hosts beginning with ns, then filter for those ending in // forcing us to query for all hosts beginning with ns, then filter for those ending in
@ -211,16 +216,16 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
"A suffix after a wildcard in a nameserver lookup must be an in-bailiwick domain"); "A suffix after a wildcard in a nameserver lookup must be an in-bailiwick domain");
} }
List<HostResource> hostList = new ArrayList<>(); List<HostResource> hostList = new ArrayList<>();
for (String fqhn : ImmutableSortedSet.copyOf(domainResource.getSubordinateHosts())) { for (String fqhn : ImmutableSortedSet.copyOf(domainResource.get().getSubordinateHosts())) {
if (cursorString.isPresent() && (fqhn.compareTo(cursorString.get()) <= 0)) { if (cursorString.isPresent() && (fqhn.compareTo(cursorString.get()) <= 0)) {
continue; continue;
} }
// We can't just check that the host name starts with the initial query string, because // 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. // then the query ns.exam*.example.com would match against nameserver ns.example.com.
if (partialStringQuery.matches(fqhn)) { if (partialStringQuery.matches(fqhn)) {
HostResource hostResource = loadByForeignKey(HostResource.class, fqhn, now); Optional<HostResource> hostResource = loadByForeignKey(HostResource.class, fqhn, now);
if ((hostResource != null) && shouldBeVisible(hostResource, now)) { if (shouldBeVisible(hostResource, now)) {
hostList.add(hostResource); hostList.add(hostResource.get());
if (hostList.size() > rdapResultSetMaxSize) { if (hostList.size() > rdapResultSetMaxSize) {
break; break;
} }
@ -230,7 +235,7 @@ public class RdapNameserverSearchAction extends RdapSearchActionBase {
return makeSearchResults( return makeSearchResults(
hostList, hostList,
IncompletenessWarningType.COMPLETE, IncompletenessWarningType.COMPLETE,
domainResource.getSubordinateHosts().size(), domainResource.get().getSubordinateHosts().size(),
CursorType.NAME, CursorType.NAME,
now); now);
} }

View file

@ -195,11 +195,14 @@ public class RdeHostLinkAction implements Runnable {
.stream() .stream()
.skip(hostName.parts().size() - (tld.get().parts().size() + 1)) .skip(hostName.parts().size() - (tld.get().parts().size() + 1))
.collect(joining(".")); .collect(joining("."));
DomainResource superordinateDomain = loadByForeignKey(DomainResource.class, domainName, now); Optional<DomainResource> superordinateDomain =
loadByForeignKey(DomainResource.class, domainName, now);
// Hosts can't be linked if domains import hasn't been run // Hosts can't be linked if domains import hasn't been run
checkState( checkState(
superordinateDomain != null, "Superordinate domain does not exist: %s", domainName); superordinateDomain.isPresent(),
return Optional.of(superordinateDomain); "Superordinate domain does not exist or is deleted: %s",
domainName);
return superordinateDomain;
} }
} }
@ -209,10 +212,4 @@ public class RdeHostLinkAction implements Runnable {
SUPERORDINATE_DOMAIN_IN_PENDING_DELETE, SUPERORDINATE_DOMAIN_IN_PENDING_DELETE,
HOST_LINKED; HOST_LINKED;
} }
private static class HostLinkException extends RuntimeException {
HostLinkException(String hostname, String xml, Throwable cause) {
super(String.format("Error linking host %s; xml=%s", hostname, xml), cause);
}
}
} }

View file

@ -31,9 +31,7 @@ final class GetApplicationCommand extends GetEppResourceCommand {
@Override @Override
public void runAndPrint() { public void runAndPrint() {
for (String applicationId : mainParameters) { mainParameters.forEach(
printResource( appId -> printResource("Application", appId, loadDomainApplication(appId, readTimestamp)));
"Application", applicationId, loadDomainApplication(applicationId, readTimestamp));
}
} }
} }

View file

@ -21,7 +21,7 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.model.EppResource; import google.registry.model.EppResource;
import javax.annotation.Nullable; import java.util.Optional;
import org.joda.time.DateTime; import org.joda.time.DateTime;
/** Abstract command to print one or more resources to stdout. */ /** Abstract command to print one or more resources to stdout. */
@ -44,16 +44,19 @@ abstract class GetEppResourceCommand implements CommandWithRemoteApi {
abstract void runAndPrint(); abstract void runAndPrint();
/** /**
* Prints a possibly-null resource to stdout, using resourceType and uniqueId to construct a * Prints a possibly-absent resource to stdout, using resourceType and uniqueId to construct a
* nice error message if the resource was null (i.e. doesn't exist). * nice error message if the resource was null (i.e. doesn't exist).
* *
* <p>The websafe key is appended to the output for use in e.g. manual mapreduce calls. * <p>The websafe key is appended to the output for use in e.g. manual mapreduce calls.
*/ */
void printResource(String resourceType, String uniqueId, @Nullable EppResource resource) { void printResource(
System.out.println(resource != null String resourceType, String uniqueId, Optional<? extends EppResource> resource) {
? String.format("%s\n\nWebsafe key: %s", System.out.println(
expand ? resource.toHydratedString() : resource, resource.isPresent()
Key.create(resource).getString()) ? String.format(
"%s\n\nWebsafe key: %s",
expand ? resource.get().toHydratedString() : resource.get(),
Key.create(resource.get()).getString())
: String.format("%s '%s' does not exist or is deleted\n", resourceType, uniqueId)); : String.format("%s '%s' does not exist or is deleted\n", resourceType, uniqueId));
} }

View file

@ -32,9 +32,7 @@ final class GetHostCommand extends GetEppResourceCommand {
@Override @Override
public void runAndPrint() { public void runAndPrint() {
for (String hostName : mainParameters) { mainParameters.forEach(
printResource( h -> printResource("Host", h, loadByForeignKey(HostResource.class, h, readTimestamp)));
"Host", hostName, loadByForeignKey(HostResource.class, hostName, readTimestamp));
}
} }
} }

View file

@ -14,9 +14,9 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
@ -28,6 +28,7 @@ import com.google.template.soy.data.SoyMapData;
import google.registry.model.domain.DomainResource; import google.registry.model.domain.DomainResource;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import google.registry.tools.soy.DomainUpdateSoyInfo; import google.registry.tools.soy.DomainUpdateSoyInfo;
import java.util.Optional;
import org.joda.time.DateTime; import org.joda.time.DateTime;
/** /**
@ -45,10 +46,11 @@ public class LockDomainCommand extends LockOrUnlockDomainCommand {
// Project all domains as of the same time so that argument order doesn't affect behavior. // Project all domains as of the same time so that argument order doesn't affect behavior.
DateTime now = DateTime.now(UTC); DateTime now = DateTime.now(UTC);
for (String domain : getDomains()) { for (String domain : getDomains()) {
DomainResource domainResource = loadByForeignKey(DomainResource.class, domain, now); Optional<DomainResource> domainResource = loadByForeignKey(DomainResource.class, domain, now);
checkArgument(domainResource != null, "Domain '%s' does not exist", domain); checkArgumentPresent(domainResource, "Domain '%s' does not exist or is deleted", domain);
ImmutableSet<StatusValue> statusesToAdd = ImmutableSet<StatusValue> statusesToAdd =
Sets.difference(REGISTRY_LOCK_STATUSES, domainResource.getStatusValues()).immutableCopy(); Sets.difference(REGISTRY_LOCK_STATUSES, domainResource.get().getStatusValues())
.immutableCopy();
if (statusesToAdd.isEmpty()) { if (statusesToAdd.isEmpty()) {
logger.atInfo().log("Domain '%s' is already locked and needs no updates.", domain); logger.atInfo().log("Domain '%s' is already locked and needs no updates.", domain);
continue; continue;

View file

@ -17,7 +17,7 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.util.CollectionUtils.findDuplicates; import static google.registry.util.CollectionUtils.findDuplicates;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
@ -27,6 +27,7 @@ import google.registry.model.domain.DomainResource;
import google.registry.tools.soy.RenewDomainSoyInfo; import google.registry.tools.soy.RenewDomainSoyInfo;
import google.registry.util.Clock; import google.registry.util.Clock;
import java.util.List; import java.util.List;
import java.util.Optional;
import javax.inject.Inject; import javax.inject.Inject;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormat;
@ -56,9 +57,11 @@ final class RenewDomainCommand extends MutatingEppToolCommand {
checkArgument(period < 10, "Cannot renew domains for 10 or more years"); checkArgument(period < 10, "Cannot renew domains for 10 or more years");
DateTime now = clock.nowUtc(); DateTime now = clock.nowUtc();
for (String domainName : mainParameters) { for (String domainName : mainParameters) {
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, now); Optional<DomainResource> domainOptional =
checkArgumentNotNull(domain, "Domain '%s' does not exist or is deleted", domainName); loadByForeignKey(DomainResource.class, domainName, now);
checkArgumentPresent(domainOptional, "Domain '%s' does not exist or is deleted", domainName);
setSoyTemplate(RenewDomainSoyInfo.getInstance(), RenewDomainSoyInfo.RENEWDOMAIN); setSoyTemplate(RenewDomainSoyInfo.getInstance(), RenewDomainSoyInfo.RENEWDOMAIN);
DomainResource domain = domainOptional.get();
addSoyRecord( addSoyRecord(
domain.getCurrentSponsorClientId(), domain.getCurrentSponsorClientId(),
new SoyMapData( new SoyMapData(

View file

@ -20,6 +20,7 @@ import static com.google.common.collect.Sets.difference;
import static google.registry.model.EppResourceUtils.checkResourcesExist; import static google.registry.model.EppResourceUtils.checkResourcesExist;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
@ -37,6 +38,7 @@ import google.registry.tools.soy.UniformRapidSuspensionSoyInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -119,17 +121,17 @@ final class UniformRapidSuspensionCommand extends MutatingEppToolCommand {
} catch (ClassCastException | ParseException e) { } catch (ClassCastException | ParseException e) {
throw new IllegalArgumentException("Invalid --dsdata JSON", e); throw new IllegalArgumentException("Invalid --dsdata JSON", e);
} }
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, now); Optional<DomainResource> domain = loadByForeignKey(DomainResource.class, domainName, now);
checkArgument(domain != null, "Domain '%s' does not exist", domainName); checkArgumentPresent(domain, "Domain '%s' does not exist or is deleted", domainName);
Set<String> missingHosts = Set<String> missingHosts =
difference(newHostsSet, checkResourcesExist(HostResource.class, newHosts, now)); difference(newHostsSet, checkResourcesExist(HostResource.class, newHosts, now));
checkArgument(missingHosts.isEmpty(), "Hosts do not exist: %s", missingHosts); checkArgument(missingHosts.isEmpty(), "Hosts do not exist: %s", missingHosts);
checkArgument( checkArgument(
locksToPreserve.isEmpty() || undo, locksToPreserve.isEmpty() || undo,
"Locks can only be preserved when running with --undo"); "Locks can only be preserved when running with --undo");
existingNameservers = getExistingNameservers(domain); existingNameservers = getExistingNameservers(domain.get());
existingLocks = getExistingLocks(domain); existingLocks = getExistingLocks(domain.get());
existingDsData = getExistingDsData(domain); existingDsData = getExistingDsData(domain.get());
setSoyTemplate( setSoyTemplate(
UniformRapidSuspensionSoyInfo.getInstance(), UniformRapidSuspensionSoyInfo.getInstance(),
UniformRapidSuspensionSoyInfo.UNIFORMRAPIDSUSPENSION); UniformRapidSuspensionSoyInfo.UNIFORMRAPIDSUSPENSION);

View file

@ -14,9 +14,9 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableList.toImmutableList;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
@ -28,6 +28,7 @@ import com.google.template.soy.data.SoyMapData;
import google.registry.model.domain.DomainResource; import google.registry.model.domain.DomainResource;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import google.registry.tools.soy.DomainUpdateSoyInfo; import google.registry.tools.soy.DomainUpdateSoyInfo;
import java.util.Optional;
import org.joda.time.DateTime; import org.joda.time.DateTime;
/** /**
@ -45,10 +46,10 @@ public class UnlockDomainCommand extends LockOrUnlockDomainCommand {
// Project all domains as of the same time so that argument order doesn't affect behavior. // Project all domains as of the same time so that argument order doesn't affect behavior.
DateTime now = DateTime.now(UTC); DateTime now = DateTime.now(UTC);
for (String domain : getDomains()) { for (String domain : getDomains()) {
DomainResource domainResource = loadByForeignKey(DomainResource.class, domain, now); Optional<DomainResource> domainResource = loadByForeignKey(DomainResource.class, domain, now);
checkArgument(domainResource != null, "Domain '%s' does not exist", domain); checkArgumentPresent(domainResource, "Domain '%s' does not exist or is deleted", domain);
ImmutableSet<StatusValue> statusesToRemove = ImmutableSet<StatusValue> statusesToRemove =
Sets.intersection(domainResource.getStatusValues(), REGISTRY_LOCK_STATUSES) Sets.intersection(domainResource.get().getStatusValues(), REGISTRY_LOCK_STATUSES)
.immutableCopy(); .immutableCopy();
if (statusesToRemove.isEmpty()) { if (statusesToRemove.isEmpty()) {
logger.atInfo().log("Domain '%s' is already unlocked and needs no updates.", domain); logger.atInfo().log("Domain '%s' is already unlocked and needs no updates.", domain);

View file

@ -43,6 +43,7 @@ import google.registry.model.reporting.HistoryEntry.Type;
import google.registry.util.Clock; import google.registry.util.Clock;
import google.registry.util.NonFinalForTesting; import google.registry.util.NonFinalForTesting;
import java.util.List; import java.util.List;
import java.util.Optional;
import javax.inject.Inject; import javax.inject.Inject;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -90,16 +91,17 @@ class UnrenewDomainCommand extends ConfirmingCommand implements CommandWithRemot
domainsNonexistentBuilder.add(domainName); domainsNonexistentBuilder.add(domainName);
continue; continue;
} }
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, now); Optional<DomainResource> domain = loadByForeignKey(DomainResource.class, domainName, now);
if (domain == null || domain.getStatusValues().contains(StatusValue.PENDING_DELETE)) { if (!domain.isPresent()
|| domain.get().getStatusValues().contains(StatusValue.PENDING_DELETE)) {
domainsDeletingBuilder.add(domainName); domainsDeletingBuilder.add(domainName);
continue; continue;
} }
domainsWithDisallowedStatusesBuilder.putAll( domainsWithDisallowedStatusesBuilder.putAll(
domainName, Sets.intersection(domain.getStatusValues(), DISALLOWED_STATUSES)); domainName, Sets.intersection(domain.get().getStatusValues(), DISALLOWED_STATUSES));
if (isBeforeOrAt( if (isBeforeOrAt(
leapSafeSubtractYears(domain.getRegistrationExpirationTime(), period), now)) { leapSafeSubtractYears(domain.get().getRegistrationExpirationTime(), period), now)) {
domainsExpiringTooSoonBuilder.put(domainName, domain.getRegistrationExpirationTime()); domainsExpiringTooSoonBuilder.put(domainName, domain.get().getRegistrationExpirationTime());
} }
} }
@ -149,13 +151,16 @@ class UnrenewDomainCommand extends ConfirmingCommand implements CommandWithRemot
private void unrenewDomain(String domainName) { private void unrenewDomain(String domainName) {
ofy().assertInTransaction(); ofy().assertInTransaction();
DateTime now = ofy().getTransactionTime(); DateTime now = ofy().getTransactionTime();
DomainResource domain = loadByForeignKey(DomainResource.class, domainName, now); Optional<DomainResource> domainOptional =
loadByForeignKey(DomainResource.class, domainName, now);
// Transactional sanity checks on the off chance that something changed between init() running // Transactional sanity checks on the off chance that something changed between init() running
// and here. // and here.
checkState( checkState(
domain != null && !domain.getStatusValues().contains(StatusValue.PENDING_DELETE), domainOptional.isPresent()
&& !domainOptional.get().getStatusValues().contains(StatusValue.PENDING_DELETE),
"Domain %s was deleted or is pending deletion", "Domain %s was deleted or is pending deletion",
domainName); domainName);
DomainResource domain = domainOptional.get();
checkState( checkState(
Sets.intersection(domain.getStatusValues(), DISALLOWED_STATUSES).isEmpty(), Sets.intersection(domain.getStatusValues(), DISALLOWED_STATUSES).isEmpty(),
"Domain %s has prohibited status values", "Domain %s has prohibited status values",

View file

@ -19,7 +19,6 @@ import static com.google.common.base.Preconditions.checkState;
import static google.registry.model.EppResourceUtils.loadDomainApplication; import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.domain.launch.ApplicationStatus.ALLOCATED; import static google.registry.model.domain.launch.ApplicationStatus.ALLOCATED;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static google.registry.util.PreconditionsUtils.checkArgumentPresent; import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
@ -83,9 +82,12 @@ final class UpdateApplicationStatusCommand extends MutatingCommand {
ofy().assertInTransaction(); ofy().assertInTransaction();
DateTime now = ofy().getTransactionTime(); DateTime now = ofy().getTransactionTime();
// Load the domain application. DomainApplication domainApplication =
DomainApplication domainApplication = loadDomainApplication(applicationId, now); loadDomainApplication(applicationId, now)
checkArgumentNotNull(domainApplication, "Domain application does not exist"); .orElseThrow(
() ->
new IllegalArgumentException(
"Domain application does not exist or is deleted"));
// It's not an error if the application already has the intended status. We want the method // It's not an error if the application already has the intended status. We want the method
// to be idempotent. // to be idempotent.

View file

@ -82,16 +82,20 @@ final class UpdateClaimsNoticeCommand implements CommandWithRemoteApi {
DateTime now = ofy().getTransactionTime(); DateTime now = ofy().getTransactionTime();
// Load the domain application. // Load the domain application.
DomainApplication domainApplication = loadDomainApplication(applicationId, now); DomainApplication domainApplication =
checkArgument(domainApplication != null, "Domain application does not exist"); loadDomainApplication(applicationId, now)
.orElseThrow(
() ->
new IllegalArgumentException(
"Domain application does not exist or is deleted"));
// Make sure this isn't a sunrise application. // Make sure this isn't a sunrise application.
checkArgument(domainApplication.getEncodedSignedMarks().isEmpty(), checkArgument(domainApplication.getEncodedSignedMarks().isEmpty(),
"Can't update claims notice on sunrise applications."); "Can't update claims notice on sunrise applications.");
// Validate the new launch notice checksum. // Validate the new launch notice checksum.
String domainLabel = InternetDomainName.from(domainApplication.getFullyQualifiedDomainName()) String domainLabel =
.parts().get(0); InternetDomainName.from(domainApplication.getFullyQualifiedDomainName()).parts().get(0);
launchNotice.validate(domainLabel); launchNotice.validate(domainLabel);
DomainApplication updatedApplication = domainApplication.asBuilder() DomainApplication updatedApplication = domainApplication.asBuilder()

View file

@ -19,7 +19,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.eppcommon.StatusValue.SERVER_UPDATE_PROHIBITED; import static google.registry.model.eppcommon.StatusValue.SERVER_UPDATE_PROHIBITED;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
@ -37,6 +37,7 @@ import google.registry.tools.soy.DomainUpdateSoyInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -172,8 +173,10 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
if (!nameservers.isEmpty() || !admins.isEmpty() || !techs.isEmpty() || !statuses.isEmpty()) { if (!nameservers.isEmpty() || !admins.isEmpty() || !techs.isEmpty() || !statuses.isEmpty()) {
DateTime now = DateTime.now(UTC); DateTime now = DateTime.now(UTC);
DomainResource domainResource = loadByForeignKey(DomainResource.class, domain, now); Optional<DomainResource> domainOptional =
checkArgumentNotNull(domainResource, "Domain '%s' does not exist", domain); loadByForeignKey(DomainResource.class, domain, now);
checkArgumentPresent(domainOptional, "Domain '%s' does not exist or is deleted", domain);
DomainResource domainResource = domainOptional.get();
checkArgument( checkArgument(
!domainResource.getStatusValues().contains(SERVER_UPDATE_PROHIBITED), !domainResource.getStatusValues().contains(SERVER_UPDATE_PROHIBITED),
"The domain '%s' has status SERVER_UPDATE_PROHIBITED. Verify that you are allowed " "The domain '%s' has status SERVER_UPDATE_PROHIBITED. Verify that you are allowed "

View file

@ -84,11 +84,16 @@ final class UpdateSmdCommand implements CommandWithRemoteApi {
DateTime now = ofy().getTransactionTime(); DateTime now = ofy().getTransactionTime();
// Load the domain application. // Load the domain application.
DomainApplication domainApplication = loadDomainApplication(applicationId, now); DomainApplication domainApplication =
checkArgument(domainApplication != null, "Domain application does not exist"); loadDomainApplication(applicationId, now)
.orElseThrow(
() ->
new IllegalArgumentException(
"Domain application does not exist or is deleted"));
// Make sure this is a sunrise application. // Make sure this is a sunrise application.
checkArgument(!domainApplication.getEncodedSignedMarks().isEmpty(), checkArgument(
!domainApplication.getEncodedSignedMarks().isEmpty(),
"Can't update SMD on a landrush application."); "Can't update SMD on a landrush application.");
// Verify the new SMD. // Verify the new SMD.

View file

@ -193,14 +193,14 @@ public class DeleteContactsAndHostsActionTest
false); false);
runMapreduce(); runMapreduce();
ContactResource contactUpdated = ContactResource contactUpdated =
loadByForeignKey(ContactResource.class, "blah8221", clock.nowUtc()); loadByForeignKey(ContactResource.class, "blah8221", clock.nowUtc()).get();
assertAboutContacts() assertAboutContacts()
.that(contactUpdated) .that(contactUpdated)
.doesNotHaveStatusValue(PENDING_DELETE) .doesNotHaveStatusValue(PENDING_DELETE)
.and() .and()
.hasDeletionTime(END_OF_TIME); .hasDeletionTime(END_OF_TIME);
DomainResource domainReloaded = DomainResource domainReloaded =
loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()); loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()).get();
assertThat(domainReloaded.getReferencedContacts()).contains(Key.create(contactUpdated)); assertThat(domainReloaded.getReferencedContacts()).contains(Key.create(contactUpdated));
HistoryEntry historyEntry = HistoryEntry historyEntry =
getOnlyHistoryEntryOfType(contactUpdated, HistoryEntry.Type.CONTACT_DELETE_FAILURE); getOnlyHistoryEntryOfType(contactUpdated, HistoryEntry.Type.CONTACT_DELETE_FAILURE);
@ -268,7 +268,7 @@ public class DeleteContactsAndHostsActionTest
Trid.create(clientTrid.orElse(null), "fakeServerTrid"), Trid.create(clientTrid.orElse(null), "fakeServerTrid"),
false); false);
runMapreduce(); runMapreduce();
assertThat(loadByForeignKey(ContactResource.class, "jim919", clock.nowUtc())).isNull(); assertThat(loadByForeignKey(ContactResource.class, "jim919", clock.nowUtc())).isEmpty();
ContactResource contactAfterDeletion = ofy().load().entity(contact).now(); ContactResource contactAfterDeletion = ofy().load().entity(contact).now();
assertAboutContacts() assertAboutContacts()
.that(contactAfterDeletion) .that(contactAfterDeletion)
@ -332,10 +332,10 @@ public class DeleteContactsAndHostsActionTest
false); false);
runMapreduce(); runMapreduce();
// Check that the contact is deleted as of now. // Check that the contact is deleted as of now.
assertThat(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())).isNull(); assertThat(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())).isEmpty();
// Check that it's still there (it wasn't deleted yesterday) and that it has history. // Check that it's still there (it wasn't deleted yesterday) and that it has history.
ContactResource softDeletedContact = ContactResource softDeletedContact =
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc().minusDays(1)); loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc().minusDays(1)).get();
assertAboutContacts() assertAboutContacts()
.that(softDeletedContact) .that(softDeletedContact)
.hasOneHistoryEntryEachOfTypes(CONTACT_TRANSFER_REQUEST, CONTACT_DELETE); .hasOneHistoryEntryEachOfTypes(CONTACT_TRANSFER_REQUEST, CONTACT_DELETE);
@ -393,9 +393,9 @@ public class DeleteContactsAndHostsActionTest
Trid.create("fakeClientTrid", "fakeServerTrid"), Trid.create("fakeClientTrid", "fakeServerTrid"),
false); false);
runMapreduce(); runMapreduce();
assertThat(loadByForeignKey(ContactResource.class, "blah1234", clock.nowUtc())).isNull(); assertThat(loadByForeignKey(ContactResource.class, "blah1234", clock.nowUtc())).isEmpty();
ContactResource contactBeforeDeletion = ContactResource contactBeforeDeletion =
loadByForeignKey(ContactResource.class, "blah1234", clock.nowUtc().minusDays(1)); loadByForeignKey(ContactResource.class, "blah1234", clock.nowUtc().minusDays(1)).get();
assertAboutContacts() assertAboutContacts()
.that(contactBeforeDeletion) .that(contactBeforeDeletion)
.isNotActiveAt(clock.nowUtc()) .isNotActiveAt(clock.nowUtc())
@ -428,7 +428,7 @@ public class DeleteContactsAndHostsActionTest
false); false);
runMapreduce(); runMapreduce();
ContactResource contactAfter = ContactResource contactAfter =
loadByForeignKey(ContactResource.class, "jane0991", clock.nowUtc()); loadByForeignKey(ContactResource.class, "jane0991", clock.nowUtc()).get();
assertAboutContacts() assertAboutContacts()
.that(contactAfter) .that(contactAfter)
.doesNotHaveStatusValue(PENDING_DELETE) .doesNotHaveStatusValue(PENDING_DELETE)
@ -455,7 +455,7 @@ public class DeleteContactsAndHostsActionTest
Trid.create("fakeClientTrid", "fakeServerTrid"), Trid.create("fakeClientTrid", "fakeServerTrid"),
true); true);
runMapreduce(); runMapreduce();
assertThat(loadByForeignKey(ContactResource.class, "nate007", clock.nowUtc())).isNull(); assertThat(loadByForeignKey(ContactResource.class, "nate007", clock.nowUtc())).isEmpty();
ContactResource contactAfterDeletion = ofy().load().entity(contact).now(); ContactResource contactAfterDeletion = ofy().load().entity(contact).now();
assertAboutContacts() assertAboutContacts()
.that(contactAfterDeletion) .that(contactAfterDeletion)
@ -561,9 +561,9 @@ public class DeleteContactsAndHostsActionTest
false); false);
enqueueMapreduceOnly(); enqueueMapreduceOnly();
assertThat(loadByForeignKey(ContactResource.class, "blah2222", clock.nowUtc())) assertThat(loadByForeignKey(ContactResource.class, "blah2222", clock.nowUtc()))
.isEqualTo(contact); .hasValue(contact);
assertThat(loadByForeignKey(HostResource.class, "rustles.your.jimmies", clock.nowUtc())) assertThat(loadByForeignKey(HostResource.class, "rustles.your.jimmies", clock.nowUtc()))
.isEqualTo(host); .hasValue(host);
assertNoTasksEnqueued(QUEUE_ASYNC_DELETE); assertNoTasksEnqueued(QUEUE_ASYNC_DELETE);
verify(action.asyncFlowMetrics).recordContactHostDeletionBatchSize(2L); verify(action.asyncFlowMetrics).recordContactHostDeletionBatchSize(2L);
verify(action.asyncFlowMetrics) verify(action.asyncFlowMetrics)
@ -610,13 +610,14 @@ public class DeleteContactsAndHostsActionTest
false); false);
runMapreduce(); runMapreduce();
HostResource hostAfter = HostResource hostAfter =
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()); loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()).get();
assertAboutHosts() assertAboutHosts()
.that(hostAfter) .that(hostAfter)
.doesNotHaveStatusValue(PENDING_DELETE) .doesNotHaveStatusValue(PENDING_DELETE)
.and() .and()
.hasDeletionTime(END_OF_TIME); .hasDeletionTime(END_OF_TIME);
DomainResource domain = loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()); DomainResource domain =
loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()).get();
assertThat(domain.getNameservers()).contains(Key.create(hostAfter)); assertThat(domain.getNameservers()).contains(Key.create(hostAfter));
HistoryEntry historyEntry = getOnlyHistoryEntryOfType(hostAfter, HOST_DELETE_FAILURE); HistoryEntry historyEntry = getOnlyHistoryEntryOfType(hostAfter, HOST_DELETE_FAILURE);
assertPollMessageFor( assertPollMessageFor(
@ -653,9 +654,9 @@ public class DeleteContactsAndHostsActionTest
Trid.create(clientTrid.orElse(null), "fakeServerTrid"), Trid.create(clientTrid.orElse(null), "fakeServerTrid"),
false); false);
runMapreduce(); runMapreduce();
assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc())).isNull(); assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc())).isEmpty();
HostResource hostBeforeDeletion = HostResource hostBeforeDeletion =
loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1)); loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1)).get();
assertAboutHosts() assertAboutHosts()
.that(hostBeforeDeletion) .that(hostBeforeDeletion)
.isNotActiveAt(clock.nowUtc()) .isNotActiveAt(clock.nowUtc())
@ -697,9 +698,9 @@ public class DeleteContactsAndHostsActionTest
Trid.create("fakeClientTrid", "fakeServerTrid"), Trid.create("fakeClientTrid", "fakeServerTrid"),
false); false);
runMapreduce(); runMapreduce();
assertThat(loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())).isNull(); assertThat(loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())).isEmpty();
HostResource hostBeforeDeletion = HostResource hostBeforeDeletion =
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc().minusDays(1)); loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc().minusDays(1)).get();
assertAboutHosts() assertAboutHosts()
.that(hostBeforeDeletion) .that(hostBeforeDeletion)
.isNotActiveAt(clock.nowUtc()) .isNotActiveAt(clock.nowUtc())
@ -743,15 +744,16 @@ public class DeleteContactsAndHostsActionTest
false); false);
runMapreduce(); runMapreduce();
// Check that the host is deleted as of now. // Check that the host is deleted as of now.
assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc())).isNull(); assertThat(loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc())).isEmpty();
assertNoBillingEvents(); assertNoBillingEvents();
assertThat( assertThat(
loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()) loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc())
.get()
.getSubordinateHosts()) .getSubordinateHosts())
.isEmpty(); .isEmpty();
assertDnsTasksEnqueued("ns2.example.tld"); assertDnsTasksEnqueued("ns2.example.tld");
HostResource hostBeforeDeletion = HostResource hostBeforeDeletion =
loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1)); loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc().minusDays(1)).get();
assertAboutHosts() assertAboutHosts()
.that(hostBeforeDeletion) .that(hostBeforeDeletion)
.isNotActiveAt(clock.nowUtc()) .isNotActiveAt(clock.nowUtc())
@ -782,7 +784,7 @@ public class DeleteContactsAndHostsActionTest
false); false);
runMapreduce(); runMapreduce();
HostResource hostAfter = HostResource hostAfter =
loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc()); loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc()).get();
assertAboutHosts() assertAboutHosts()
.that(hostAfter) .that(hostAfter)
.doesNotHaveStatusValue(PENDING_DELETE) .doesNotHaveStatusValue(PENDING_DELETE)
@ -809,9 +811,9 @@ public class DeleteContactsAndHostsActionTest
Trid.create("fakeClientTrid", "fakeServerTrid"), Trid.create("fakeClientTrid", "fakeServerTrid"),
true); true);
runMapreduce(); runMapreduce();
assertThat(loadByForeignKey(HostResource.class, "ns66.example.tld", clock.nowUtc())).isNull(); assertThat(loadByForeignKey(HostResource.class, "ns66.example.tld", clock.nowUtc())).isEmpty();
HostResource hostBeforeDeletion = HostResource hostBeforeDeletion =
loadByForeignKey(HostResource.class, "ns66.example.tld", clock.nowUtc().minusDays(1)); loadByForeignKey(HostResource.class, "ns66.example.tld", clock.nowUtc().minusDays(1)).get();
assertAboutHosts() assertAboutHosts()
.that(hostBeforeDeletion) .that(hostBeforeDeletion)
.isNotActiveAt(clock.nowUtc()) .isNotActiveAt(clock.nowUtc())

View file

@ -15,6 +15,7 @@
package google.registry.batch; package google.registry.batch;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
@ -46,6 +47,7 @@ import google.registry.model.registry.Registry.TldType;
import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry;
import google.registry.testing.FakeResponse; import google.registry.testing.FakeResponse;
import google.registry.testing.mapreduce.MapreduceTestCase; import google.registry.testing.mapreduce.MapreduceTestCase;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import org.joda.money.Money; import org.joda.money.Money;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -190,7 +192,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
runMapreduce(); runMapreduce();
DateTime timeAfterDeletion = DateTime.now(UTC); DateTime timeAfterDeletion = DateTime.now(UTC);
assertThat(loadByForeignKey(DomainResource.class, "blah.ib-any.test", timeAfterDeletion)) assertThat(loadByForeignKey(DomainResource.class, "blah.ib-any.test", timeAfterDeletion))
.isNull(); .isEmpty();
assertThat(ofy().load().entity(domain).now().getDeletionTime()).isLessThan(timeAfterDeletion); assertThat(ofy().load().entity(domain).now().getDeletionTime()).isLessThan(timeAfterDeletion);
assertDnsTasksEnqueued("blah.ib-any.test"); assertDnsTasksEnqueued("blah.ib-any.test");
} }
@ -207,7 +209,7 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
resetAction(); resetAction();
runMapreduce(); runMapreduce();
assertThat(loadByForeignKey(DomainResource.class, "blah.ib-any.test", timeAfterDeletion)) assertThat(loadByForeignKey(DomainResource.class, "blah.ib-any.test", timeAfterDeletion))
.isNull(); .isEmpty();
assertThat(ofy().load().entity(domain).now().getDeletionTime()).isLessThan(timeAfterDeletion); assertThat(ofy().load().entity(domain).now().getDeletionTime()).isLessThan(timeAfterDeletion);
assertDnsTasksEnqueued("blah.ib-any.test"); assertDnsTasksEnqueued("blah.ib-any.test");
} }
@ -220,10 +222,10 @@ public class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDa
.setCreationTimeForTest(DateTime.now(UTC).minusSeconds(1)) .setCreationTimeForTest(DateTime.now(UTC).minusSeconds(1))
.build()); .build());
runMapreduce(); runMapreduce();
DomainResource domain = Optional<DomainResource> domain =
loadByForeignKey(DomainResource.class, "blah.ib-any.test", DateTime.now(UTC)); loadByForeignKey(DomainResource.class, "blah.ib-any.test", DateTime.now(UTC));
assertThat(domain).isNotNull(); assertThat(domain).isPresent();
assertThat(domain.getDeletionTime()).isEqualTo(END_OF_TIME); assertThat(domain.get().getDeletionTime()).isEqualTo(END_OF_TIME);
} }
@Test @Test

View file

@ -250,7 +250,7 @@ public class DnsUpdateWriterTest {
newDomainResource("example.tld") newDomainResource("example.tld")
.asBuilder() .asBuilder()
.addSubordinateHost("ns1.example.tld") .addSubordinateHost("ns1.example.tld")
.addNameservers(ImmutableSet.of(Key.create(host))) .addNameserver(Key.create(host))
.build()); .build());
writer.publishHost("ns1.example.tld"); writer.publishHost("ns1.example.tld");
@ -358,7 +358,7 @@ public class DnsUpdateWriterTest {
.asBuilder() .asBuilder()
.addSubordinateHost("ns1.example.tld") .addSubordinateHost("ns1.example.tld")
.addSubordinateHost("foo.example.tld") .addSubordinateHost("foo.example.tld")
.addNameservers(ImmutableSet.of(Key.create(inBailiwickNameserver))) .addNameserver(Key.create(inBailiwickNameserver))
.build()); .build());
writer.publishDomain("example.tld"); writer.publishDomain("example.tld");

View file

@ -107,7 +107,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
"EXDATE", "2002-06-01T00:02:00.0Z")); "EXDATE", "2002-06-01T00:02:00.0Z"));
DomainResource domain = DomainResource domain =
loadByForeignKey(DomainResource.class, "example.tld", createTime.plusHours(1)); loadByForeignKey(DomainResource.class, "example.tld", createTime.plusHours(1)).get();
// Delete domain example.tld within the add grace period. // Delete domain example.tld within the add grace period.
DateTime deleteTime = createTime.plusDays(1); DateTime deleteTime = createTime.plusDays(1);
@ -184,7 +184,8 @@ public class EppLifecycleDomainTest extends EppTestCase {
DomainResource domain = DomainResource domain =
loadByForeignKey( loadByForeignKey(
DomainResource.class, "example.tld", DateTime.parse("2000-08-01T00:02:00Z")); DomainResource.class, "example.tld", DateTime.parse("2000-08-01T00:02:00Z"))
.get();
// Verify that the autorenew was ended and that the one-time billing event is not canceled. // Verify that the autorenew was ended and that the one-time billing event is not canceled.
assertBillingEventsForResource( assertBillingEventsForResource(
domain, domain,
@ -218,7 +219,8 @@ public class EppLifecycleDomainTest extends EppTestCase {
DomainResource domain = DomainResource domain =
loadByForeignKey( loadByForeignKey(
DomainResource.class, "example.tld", DateTime.parse("2000-06-01T00:03:00Z")); DomainResource.class, "example.tld", DateTime.parse("2000-06-01T00:03:00Z"))
.get();
// Delete domain example.tld within the add grade period. // Delete domain example.tld within the add grade period.
DateTime deleteTime = createTime.plusDays(1); DateTime deleteTime = createTime.plusDays(1);

View file

@ -218,9 +218,9 @@ public class EppLifecycleHostTest extends EppTestCase {
DateTime timeAfterCreates = DateTime.parse("2000-06-01T00:06:00Z"); DateTime timeAfterCreates = DateTime.parse("2000-06-01T00:06:00Z");
HostResource exampleBarFooTldHost = HostResource exampleBarFooTldHost =
loadByForeignKey(HostResource.class, "ns1.example.bar.foo.tld", timeAfterCreates); loadByForeignKey(HostResource.class, "ns1.example.bar.foo.tld", timeAfterCreates).get();
DomainResource exampleBarFooTldDomain = DomainResource exampleBarFooTldDomain =
loadByForeignKey(DomainResource.class, "example.bar.foo.tld", timeAfterCreates); loadByForeignKey(DomainResource.class, "example.bar.foo.tld", timeAfterCreates).get();
assertAboutHosts() assertAboutHosts()
.that(exampleBarFooTldHost) .that(exampleBarFooTldHost)
.hasSuperordinateDomain(Key.create(exampleBarFooTldDomain)); .hasSuperordinateDomain(Key.create(exampleBarFooTldDomain));
@ -228,18 +228,18 @@ public class EppLifecycleHostTest extends EppTestCase {
.containsExactly("ns1.example.bar.foo.tld"); .containsExactly("ns1.example.bar.foo.tld");
HostResource exampleFooTldHost = HostResource exampleFooTldHost =
loadByForeignKey(HostResource.class, "ns1.example.foo.tld", timeAfterCreates); loadByForeignKey(HostResource.class, "ns1.example.foo.tld", timeAfterCreates).get();
DomainResource exampleFooTldDomain = DomainResource exampleFooTldDomain =
loadByForeignKey(DomainResource.class, "example.foo.tld", timeAfterCreates); loadByForeignKey(DomainResource.class, "example.foo.tld", timeAfterCreates).get();
assertAboutHosts() assertAboutHosts()
.that(exampleFooTldHost) .that(exampleFooTldHost)
.hasSuperordinateDomain(Key.create(exampleFooTldDomain)); .hasSuperordinateDomain(Key.create(exampleFooTldDomain));
assertThat(exampleFooTldDomain.getSubordinateHosts()).containsExactly("ns1.example.foo.tld"); assertThat(exampleFooTldDomain.getSubordinateHosts()).containsExactly("ns1.example.foo.tld");
HostResource exampleTldHost = HostResource exampleTldHost =
loadByForeignKey(HostResource.class, "ns1.example.tld", timeAfterCreates); loadByForeignKey(HostResource.class, "ns1.example.tld", timeAfterCreates).get();
DomainResource exampleTldDomain = DomainResource exampleTldDomain =
loadByForeignKey(DomainResource.class, "example.tld", timeAfterCreates); loadByForeignKey(DomainResource.class, "example.tld", timeAfterCreates).get();
assertAboutHosts().that(exampleTldHost).hasSuperordinateDomain(Key.create(exampleTldDomain)); assertAboutHosts().that(exampleTldHost).hasSuperordinateDomain(Key.create(exampleTldDomain));
assertThat(exampleTldDomain.getSubordinateHosts()).containsExactly("ns1.example.tld"); assertThat(exampleTldDomain.getSubordinateHosts()).containsExactly("ns1.example.tld");

View file

@ -17,6 +17,7 @@ package google.registry.flows;
import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.tmch.ClaimsListShardTest.createTestClaimsListShard; import static google.registry.model.tmch.ClaimsListShardTest.createTestClaimsListShard;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
@ -32,7 +33,6 @@ import com.google.common.testing.TestLogHandler;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.flows.FlowUtils.NotLoggedInException; import google.registry.flows.FlowUtils.NotLoggedInException;
import google.registry.model.EppResource; import google.registry.model.EppResource;
import google.registry.model.EppResourceUtils;
import google.registry.model.domain.DomainApplication; import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.launch.ApplicationIdTargetExtension; import google.registry.model.domain.launch.ApplicationIdTargetExtension;
import google.registry.model.eppcommon.Trid; import google.registry.model.eppcommon.Trid;
@ -46,6 +46,7 @@ import google.registry.testing.TaskQueueHelper.TaskMatcher;
import google.registry.util.TypeUtils.TypeInstantiator; import google.registry.util.TypeUtils.TypeInstantiator;
import java.util.Optional; import java.util.Optional;
import java.util.logging.Level; import java.util.logging.Level;
import javax.annotation.Nullable;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
@ -71,20 +72,22 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
LoggerConfig.getConfig("").addHandler(logHandler); LoggerConfig.getConfig("").addHandler(logHandler);
} }
@Nullable
protected R reloadResourceByForeignKey(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 Datastore and not // Force the session to be cleared so that when we read it back, we read from Datastore and not
// from the transaction's session cache. // from the transaction's session cache.
ofy().clearSessionCache(); ofy().clearSessionCache();
return loadByForeignKey(getResourceClass(), getUniqueIdFromCommand(), now); return loadByForeignKey(getResourceClass(), getUniqueIdFromCommand(), now).orElse(null);
} }
@Nullable
protected R reloadResourceByForeignKey() throws Exception { protected R reloadResourceByForeignKey() throws Exception {
return reloadResourceByForeignKey(clock.nowUtc()); return reloadResourceByForeignKey(clock.nowUtc());
} }
protected DomainApplication reloadDomainApplication() throws Exception { protected DomainApplication reloadDomainApplication() throws Exception {
ofy().clearSessionCache(); ofy().clearSessionCache();
return EppResourceUtils.loadDomainApplication(getUniqueIdFromCommand(), clock.nowUtc()); return loadDomainApplication(getUniqueIdFromCommand(), clock.nowUtc()).get();
} }
protected <T extends EppResource> T reloadResourceAndCloneAtTime(T resource, DateTime now) { protected <T extends EppResource> T reloadResourceAndCloneAtTime(T resource, DateTime now) {

View file

@ -150,7 +150,7 @@ public class DomainAllocateFlowTest
boolean sunrushAddGracePeriod = (nameservers == 0); boolean sunrushAddGracePeriod = (nameservers == 0);
// The application should be marked as allocated, with a new history entry. // The application should be marked as allocated, with a new history entry.
DomainApplication application = loadDomainApplication(applicationId, clock.nowUtc()); DomainApplication application = loadDomainApplication(applicationId, clock.nowUtc()).get();
assertAboutApplications().that(application) assertAboutApplications().that(application)
.hasApplicationStatus(ApplicationStatus.ALLOCATED).and() .hasApplicationStatus(ApplicationStatus.ALLOCATED).and()
.hasHistoryEntryAtIndex(0) .hasHistoryEntryAtIndex(0)

View file

@ -15,8 +15,10 @@
package google.registry.flows.domain; package google.registry.flows.domain;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EppResourceUtils.isLinked; import static google.registry.model.EppResourceUtils.isLinked;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey; import static google.registry.model.index.ForeignKeyIndex.loadAndGetKey;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
@ -72,7 +74,7 @@ public class DomainApplicationDeleteFlowTest
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlowAssertResponse(loadFile("generic_success_response.xml")); runFlowAssertResponse(loadFile("generic_success_response.xml"));
// Check that the domain is fully deleted. // Check that the domain is fully deleted.
assertThat(reloadDomainApplication()).isNull(); assertThat(loadDomainApplication(getUniqueIdFromCommand(), clock.nowUtc())).isEmpty();
assertNoBillingEvents(); assertNoBillingEvents();
} }
@ -93,11 +95,10 @@ public class DomainApplicationDeleteFlowTest
.asBuilder() .asBuilder()
.setRepoId("1-TLD") .setRepoId("1-TLD")
.setRegistrant( .setRegistrant(
Key.create(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))) Key.create(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()).get()))
.setNameservers( .setNameservers(
ImmutableSet.of(
Key.create( Key.create(
loadByForeignKey(HostResource.class, "ns1.example.net", clock.nowUtc())))) loadByForeignKey(HostResource.class, "ns1.example.net", clock.nowUtc()).get()))
.build()); .build());
doSuccessfulTest(); doSuccessfulTest();
for (Key<? extends EppResource> key : for (Key<? extends EppResource> key :

View file

@ -112,16 +112,15 @@ public class DomainApplicationUpdateFlowTest
} }
private DomainApplication persistApplication() { private DomainApplication persistApplication() {
HostResource host =
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()).get();
return persistResource( return persistResource(
newApplicationBuilder() newApplicationBuilder()
.setContacts( .setContacts(
ImmutableSet.of( ImmutableSet.of(
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)), DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)),
DesignatedContact.create(Type.ADMIN, Key.create(unusedContact)))) DesignatedContact.create(Type.ADMIN, Key.create(unusedContact))))
.setNameservers( .setNameservers(ImmutableSet.of(Key.create(host)))
ImmutableSet.of(
Key.create(
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
.build()); .build());
} }
@ -184,7 +183,8 @@ public class DomainApplicationUpdateFlowTest
public void testSuccess_registrantMovedToTechContact() throws Exception { public void testSuccess_registrantMovedToTechContact() throws Exception {
setEppInput("domain_update_sunrise_registrant_to_tech.xml"); setEppInput("domain_update_sunrise_registrant_to_tech.xml");
persistReferencedEntities(); persistReferencedEntities();
ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()); ContactResource sh8013 =
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()).get();
persistResource(newApplicationBuilder().setRegistrant(Key.create(sh8013)).build()); persistResource(newApplicationBuilder().setRegistrant(Key.create(sh8013)).build());
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlowAssertResponse(loadFile("generic_success_response.xml")); runFlowAssertResponse(loadFile("generic_success_response.xml"));
@ -194,7 +194,8 @@ public class DomainApplicationUpdateFlowTest
public void testSuccess_multipleReferencesToSameContactRemoved() throws Exception { public void testSuccess_multipleReferencesToSameContactRemoved() throws Exception {
setEppInput("domain_update_sunrise_remove_multiple_contacts.xml"); setEppInput("domain_update_sunrise_remove_multiple_contacts.xml");
persistReferencedEntities(); persistReferencedEntities();
ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()); ContactResource sh8013 =
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()).get();
Key<ContactResource> sh8013Key = Key.create(sh8013); Key<ContactResource> sh8013Key = Key.create(sh8013);
persistResource( persistResource(
newApplicationBuilder() newApplicationBuilder()
@ -411,7 +412,8 @@ public class DomainApplicationUpdateFlowTest
nameservers.add( nameservers.add(
Key.create( Key.create(
loadByForeignKey( loadByForeignKey(
HostResource.class, String.format("ns%d.example.tld", i), clock.nowUtc()))); HostResource.class, String.format("ns%d.example.tld", i), clock.nowUtc())
.get()));
} }
} }
persistResource( persistResource(
@ -546,7 +548,7 @@ public class DomainApplicationUpdateFlowTest
DesignatedContact.create( DesignatedContact.create(
Type.TECH, Type.TECH,
Key.create( Key.create(
loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))) loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()).get()))))
.build()); .build());
EppException thrown = assertThrows(DuplicateContactForRoleException.class, this::runFlow); EppException thrown = assertThrows(DuplicateContactForRoleException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
@ -639,7 +641,8 @@ public class DomainApplicationUpdateFlowTest
.setNameservers( .setNameservers(
ImmutableSet.of( ImmutableSet.of(
Key.create( Key.create(
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())))) loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())
.get())))
.build()); .build());
EppException thrown = assertThrows(AddRemoveSameValueException.class, this::runFlow); EppException thrown = assertThrows(AddRemoveSameValueException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
@ -656,7 +659,8 @@ public class DomainApplicationUpdateFlowTest
DesignatedContact.create( DesignatedContact.create(
Type.TECH, Type.TECH,
Key.create( Key.create(
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))))) loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())
.get()))))
.build()); .build());
EppException thrown = assertThrows(AddRemoveSameValueException.class, this::runFlow); EppException thrown = assertThrows(AddRemoveSameValueException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
@ -759,10 +763,9 @@ public class DomainApplicationUpdateFlowTest
persistResource( persistResource(
reloadDomainApplication() reloadDomainApplication()
.asBuilder() .asBuilder()
.addNameservers( .addNameserver(
ImmutableSet.of(
Key.create( Key.create(
loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc())))) loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc()).get()))
.build()); .build());
persistResource( persistResource(
Registry.get("tld") Registry.get("tld")
@ -833,10 +836,9 @@ public class DomainApplicationUpdateFlowTest
persistResource( persistResource(
reloadDomainApplication() reloadDomainApplication()
.asBuilder() .asBuilder()
.addNameservers( .addNameserver(
ImmutableSet.of(
Key.create( Key.create(
loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc())))) loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc()).get()))
.build()); .build());
persistResource( persistResource(
Registry.get("tld") Registry.get("tld")

View file

@ -692,6 +692,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
HostResource host = persistResource(newHostResource("ns1.example.tld")); HostResource host = persistResource(newHostResource("ns1.example.tld"));
persistResource( persistResource(
loadByForeignKey(DomainResource.class, getUniqueIdFromCommand(), clock.nowUtc()) loadByForeignKey(DomainResource.class, getUniqueIdFromCommand(), clock.nowUtc())
.get()
.asBuilder() .asBuilder()
.setNameservers(ImmutableSet.of(Key.create(host))) .setNameservers(ImmutableSet.of(Key.create(host)))
.build()); .build());
@ -700,7 +701,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
newDomainResource("example1.tld") newDomainResource("example1.tld")
.asBuilder() .asBuilder()
.setRegistrant( .setRegistrant(
Key.create(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))) Key.create(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()).get()))
.setNameservers(ImmutableSet.of(Key.create(host))) .setNameservers(ImmutableSet.of(Key.create(host)))
.setDeletionTime(START_OF_TIME) .setDeletionTime(START_OF_TIME)
.build()); .build());

View file

@ -124,7 +124,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
} }
private DomainResource persistDomain() throws Exception { private DomainResource persistDomain() throws Exception {
HostResource host = loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()); HostResource host =
loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()).get();
DomainResource domain = DomainResource domain =
persistResource( persistResource(
newDomainResource(getUniqueIdFromCommand()) newDomainResource(getUniqueIdFromCommand())
@ -227,7 +228,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
getOnlyHistoryEntryOfType(resource, HistoryEntry.Type.DOMAIN_UPDATE); getOnlyHistoryEntryOfType(resource, HistoryEntry.Type.DOMAIN_UPDATE);
assertThat(resource.getNameservers()) assertThat(resource.getNameservers())
.containsExactly( .containsExactly(
Key.create(loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()))); Key.create(
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()).get()));
BillingEvent.OneTime regularAddBillingEvent = BillingEvent.OneTime regularAddBillingEvent =
new BillingEvent.OneTime.Builder() new BillingEvent.OneTime.Builder()
.setReason(Reason.CREATE) .setReason(Reason.CREATE)
@ -283,7 +285,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistResource( persistResource(
reloadResourceByForeignKey() reloadResourceByForeignKey()
.asBuilder() .asBuilder()
.setNameservers(null) .setNameservers(ImmutableSet.of())
.addGracePeriod( .addGracePeriod(
GracePeriod.forBillingEvent(GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent)) GracePeriod.forBillingEvent(GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent))
.build()); .build());
@ -308,7 +310,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistResource( persistResource(
reloadResourceByForeignKey() reloadResourceByForeignKey()
.asBuilder() .asBuilder()
.setNameservers(null) .setNameservers(ImmutableSet.of())
.addGracePeriod( .addGracePeriod(
GracePeriod.forBillingEvent(GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent)) GracePeriod.forBillingEvent(GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent))
.build()); .build());
@ -329,9 +331,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
reloadResourceByForeignKey() reloadResourceByForeignKey()
.asBuilder() .asBuilder()
.setNameservers( .setNameservers(
ImmutableSet.of(
Key.create( Key.create(
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc())))) loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()).get()))
.addGracePeriod( .addGracePeriod(
GracePeriod.forBillingEvent(GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent)) GracePeriod.forBillingEvent(GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent))
.addStatusValue(StatusValue.SERVER_HOLD) .addStatusValue(StatusValue.SERVER_HOLD)
@ -356,9 +357,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
reloadResourceByForeignKey() reloadResourceByForeignKey()
.asBuilder() .asBuilder()
.setNameservers( .setNameservers(
ImmutableSet.of(
Key.create( Key.create(
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc())))) loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()).get()))
.addGracePeriod( .addGracePeriod(
GracePeriod.forBillingEvent(GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent)) GracePeriod.forBillingEvent(GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent))
.addStatusValue(StatusValue.CLIENT_HOLD) .addStatusValue(StatusValue.CLIENT_HOLD)
@ -383,7 +383,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistResource( persistResource(
reloadResourceByForeignKey() reloadResourceByForeignKey()
.asBuilder() .asBuilder()
.setNameservers(null) .setNameservers(ImmutableSet.of())
.addGracePeriod( .addGracePeriod(
GracePeriod.forBillingEvent(GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent)) GracePeriod.forBillingEvent(GracePeriodStatus.SUNRUSH_ADD, sunrushAddBillingEvent))
.addStatusValue(StatusValue.SERVER_HOLD) .addStatusValue(StatusValue.SERVER_HOLD)
@ -407,7 +407,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
nameservers.add( nameservers.add(
Key.create( Key.create(
loadByForeignKey( loadByForeignKey(
HostResource.class, String.format("ns%d.example.foo", i), clock.nowUtc()))); HostResource.class, String.format("ns%d.example.foo", i), clock.nowUtc())
.get()));
} }
} }
persistResource( persistResource(
@ -523,8 +524,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setNameservers( .setNameservers(
ImmutableSet.of( ImmutableSet.of(
Key.create( Key.create(
loadByForeignKey( loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())
HostResource.class, "ns1.example.tld", clock.nowUtc())))) .get())))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
assertTransactionalFlow(true); assertTransactionalFlow(true);
@ -532,8 +533,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
domain = reloadResourceByForeignKey(); domain = reloadResourceByForeignKey();
assertThat(domain.getNameservers()).containsExactly(Key.create(addedHost)); assertThat(domain.getNameservers()).containsExactly(Key.create(addedHost));
assertThat(domain.getSubordinateHosts()).containsExactly("ns1.example.tld", "ns2.example.tld"); assertThat(domain.getSubordinateHosts()).containsExactly("ns1.example.tld", "ns2.example.tld");
existingHost = loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()); existingHost = loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()).get();
addedHost = loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc()); addedHost = loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc()).get();
assertThat(existingHost.getSuperordinateDomain()).isEqualTo(Key.create(domain)); assertThat(existingHost.getSuperordinateDomain()).isEqualTo(Key.create(domain));
assertThat(addedHost.getSuperordinateDomain()).isEqualTo(Key.create(domain)); assertThat(addedHost.getSuperordinateDomain()).isEqualTo(Key.create(domain));
} }
@ -542,7 +543,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
public void testSuccess_registrantMovedToTechContact() throws Exception { public void testSuccess_registrantMovedToTechContact() throws Exception {
setEppInput("domain_update_registrant_to_tech.xml"); setEppInput("domain_update_registrant_to_tech.xml");
persistReferencedEntities(); persistReferencedEntities();
ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()); ContactResource sh8013 =
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()).get();
persistResource( persistResource(
newDomainResource(getUniqueIdFromCommand()) newDomainResource(getUniqueIdFromCommand())
.asBuilder() .asBuilder()
@ -556,7 +558,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
public void testSuccess_multipleReferencesToSameContactRemoved() throws Exception { public void testSuccess_multipleReferencesToSameContactRemoved() throws Exception {
setEppInput("domain_update_remove_multiple_contacts.xml"); setEppInput("domain_update_remove_multiple_contacts.xml");
persistReferencedEntities(); persistReferencedEntities();
ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()); ContactResource sh8013 =
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()).get();
Key<ContactResource> sh8013Key = Key.create(sh8013); Key<ContactResource> sh8013Key = Key.create(sh8013);
persistResource( persistResource(
newDomainResource(getUniqueIdFromCommand()) newDomainResource(getUniqueIdFromCommand())
@ -936,11 +939,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
reloadResourceByForeignKey() reloadResourceByForeignKey()
.asBuilder() .asBuilder()
.setContacts( .setContacts(
ImmutableSet.of(
DesignatedContact.create( DesignatedContact.create(
Type.TECH, Type.TECH,
Key.create( Key.create(
loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))) loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()).get())))
.build()); .build());
EppException thrown = assertThrows(DuplicateContactForRoleException.class, this::runFlow); EppException thrown = assertThrows(DuplicateContactForRoleException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
@ -1114,7 +1116,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setNameservers( .setNameservers(
ImmutableSet.of( ImmutableSet.of(
Key.create( Key.create(
loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc())))) loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc())
.get())))
.build()); .build());
EppException thrown = assertThrows(AddRemoveSameValueException.class, this::runFlow); EppException thrown = assertThrows(AddRemoveSameValueException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
@ -1128,11 +1131,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
newDomainResource(getUniqueIdFromCommand()) newDomainResource(getUniqueIdFromCommand())
.asBuilder() .asBuilder()
.setContacts( .setContacts(
ImmutableSet.of(
DesignatedContact.create( DesignatedContact.create(
Type.TECH, Type.TECH,
Key.create( Key.create(
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))))) loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()).get())))
.build()); .build());
EppException thrown = assertThrows(AddRemoveSameValueException.class, this::runFlow); EppException thrown = assertThrows(AddRemoveSameValueException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
@ -1179,6 +1181,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistActiveContact("sh8013"); persistActiveContact("sh8013");
persistResource( persistResource(
loadByForeignKey(ContactResource.class, "mak21", clock.nowUtc()) loadByForeignKey(ContactResource.class, "mak21", clock.nowUtc())
.get()
.asBuilder() .asBuilder()
.addStatusValue(StatusValue.PENDING_DELETE) .addStatusValue(StatusValue.PENDING_DELETE)
.build()); .build());
@ -1197,6 +1200,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistActiveContact("sh8013"); persistActiveContact("sh8013");
persistResource( persistResource(
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()) loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc())
.get()
.asBuilder() .asBuilder()
.addStatusValue(StatusValue.PENDING_DELETE) .addStatusValue(StatusValue.PENDING_DELETE)
.build()); .build());
@ -1249,11 +1253,13 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.build()); .build());
assertThat(reloadResourceByForeignKey().getNameservers()) assertThat(reloadResourceByForeignKey().getNameservers())
.doesNotContain( .doesNotContain(
Key.create(loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()))); Key.create(
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()).get()));
runFlow(); runFlow();
assertThat(reloadResourceByForeignKey().getNameservers()) assertThat(reloadResourceByForeignKey().getNameservers())
.contains( .contains(
Key.create(loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()))); Key.create(
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()).get()));
} }
@Test @Test
@ -1294,10 +1300,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistResource( persistResource(
reloadResourceByForeignKey() reloadResourceByForeignKey()
.asBuilder() .asBuilder()
.addNameservers( .addNameserver(
ImmutableSet.of(
Key.create( Key.create(
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc())))) loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()).get()))
.build()); .build());
persistResource( persistResource(
Registry.get("tld") Registry.get("tld")
@ -1307,12 +1312,14 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.build()); .build());
assertThat(reloadResourceByForeignKey().getNameservers()) assertThat(reloadResourceByForeignKey().getNameservers())
.contains( .contains(
Key.create(loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()))); Key.create(
loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()).get()));
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlow(); runFlow();
assertThat(reloadResourceByForeignKey().getNameservers()) assertThat(reloadResourceByForeignKey().getNameservers())
.doesNotContain( .doesNotContain(
Key.create(loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()))); Key.create(
loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()).get()));
} }
@Test @Test
@ -1387,10 +1394,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistResource( persistResource(
reloadResourceByForeignKey() reloadResourceByForeignKey()
.asBuilder() .asBuilder()
.addNameservers( .addNameserver(
ImmutableSet.of(
Key.create( Key.create(
loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc())))) loadByForeignKey(HostResource.class, "ns2.example.foo", clock.nowUtc()).get()))
.build()); .build());
persistResource( persistResource(
Registry.get("tld") Registry.get("tld")
@ -1401,12 +1407,14 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.build()); .build());
assertThat(reloadResourceByForeignKey().getNameservers()) assertThat(reloadResourceByForeignKey().getNameservers())
.contains( .contains(
Key.create(loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()))); Key.create(
loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()).get()));
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlow(); runFlow();
assertThat(reloadResourceByForeignKey().getNameservers()) assertThat(reloadResourceByForeignKey().getNameservers())
.doesNotContain( .doesNotContain(
Key.create(loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()))); Key.create(
loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()).get()));
} }
@Test @Test

View file

@ -116,7 +116,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
doSuccessfulInternalTest("tld"); doSuccessfulInternalTest("tld");
HostResource host = reloadResourceByForeignKey(); HostResource host = reloadResourceByForeignKey();
DomainResource superordinateDomain = DomainResource superordinateDomain =
loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()); loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()).get();
assertAboutHosts().that(host).hasSuperordinateDomain(Key.create(superordinateDomain)); assertAboutHosts().that(host).hasSuperordinateDomain(Key.create(superordinateDomain));
assertThat(superordinateDomain.getSubordinateHosts()).containsExactly("ns1.example.tld"); assertThat(superordinateDomain.getSubordinateHosts()).containsExactly("ns1.example.tld");
assertDnsTasksEnqueued("ns1.example.tld"); assertDnsTasksEnqueued("ns1.example.tld");
@ -145,7 +145,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
doSuccessfulInternalTest("tld"); doSuccessfulInternalTest("tld");
HostResource host = reloadResourceByForeignKey(); HostResource host = reloadResourceByForeignKey();
DomainResource superordinateDomain = DomainResource superordinateDomain =
loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()); loadByForeignKey(DomainResource.class, "example.tld", clock.nowUtc()).get();
assertAboutHosts().that(host).hasSuperordinateDomain(Key.create(superordinateDomain)); assertAboutHosts().that(host).hasSuperordinateDomain(Key.create(superordinateDomain));
assertThat(superordinateDomain.getSubordinateHosts()).containsExactly("ns1.example.tld"); assertThat(superordinateDomain.getSubordinateHosts()).containsExactly("ns1.example.tld");
assertDnsTasksEnqueued("ns1.example.tld"); assertDnsTasksEnqueued("ns1.example.tld");

View file

@ -92,7 +92,7 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
persistResource( persistResource(
newDomainResource("example.foobar") newDomainResource("example.foobar")
.asBuilder() .asBuilder()
.addNameservers(ImmutableSet.of(Key.create(persistHostResource()))) .addNameserver(Key.create(persistHostResource()))
.build()); .build());
assertTransactionalFlow(false); assertTransactionalFlow(false);
// Check that the persisted host info was returned. // Check that the persisted host info was returned.

View file

@ -159,7 +159,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
assertThat(reloadResourceByForeignKey()).isNull(); assertThat(reloadResourceByForeignKey()).isNull();
// However, it should load correctly if we use the new name (taken from the xml). // However, it should load correctly if we use the new name (taken from the xml).
HostResource renamedHost = HostResource renamedHost =
loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc()); loadByForeignKey(HostResource.class, "ns2.example.tld", clock.nowUtc()).get();
assertAboutHosts() assertAboutHosts()
.that(renamedHost) .that(renamedHost)
.hasOnlyOneHistoryEntryWhich() .hasOnlyOneHistoryEntryWhich()

View file

@ -15,6 +15,8 @@
package google.registry.model; package google.registry.model;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
@ -40,9 +42,8 @@ public class EppResourceTest extends EntityTestCase {
persistResource(originalContact.asBuilder().setEmailAddress("different@fake.lol").build()); persistResource(originalContact.asBuilder().setEmailAddress("different@fake.lol").build());
assertThat(EppResource.loadCached(ImmutableList.of(Key.create(originalContact)))) assertThat(EppResource.loadCached(ImmutableList.of(Key.create(originalContact))))
.containsExactly(Key.create(originalContact), originalContact); .containsExactly(Key.create(originalContact), originalContact);
assertThat( assertThat(loadByForeignKey(ContactResource.class, "contact123", clock.nowUtc()))
EppResourceUtils.loadByForeignKey(ContactResource.class, "contact123", clock.nowUtc())) .hasValue(modifiedContact);
.isEqualTo(modifiedContact);
} }
@Test @Test
@ -56,10 +57,8 @@ public class EppResourceTest extends EntityTestCase {
originalHost.asBuilder().setLastTransferTime(clock.nowUtc().minusDays(60)).build()); originalHost.asBuilder().setLastTransferTime(clock.nowUtc().minusDays(60)).build());
assertThat(EppResource.loadCached(ImmutableList.of(Key.create(originalHost)))) assertThat(EppResource.loadCached(ImmutableList.of(Key.create(originalHost))))
.containsExactly(Key.create(originalHost), originalHost); .containsExactly(Key.create(originalHost), originalHost);
assertThat( assertThat(loadByForeignKey(HostResource.class, "ns1.example.com", clock.nowUtc()))
EppResourceUtils.loadByForeignKey( .hasValue(modifiedHost);
HostResource.class, "ns1.example.com", clock.nowUtc()))
.isEqualTo(modifiedHost);
} }
private static void setNonZeroCachingInterval() { private static void setNonZeroCachingInterval() {

View file

@ -15,6 +15,7 @@
package google.registry.model.contact; package google.registry.model.contact;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps; import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps;
@ -112,7 +113,7 @@ public class ContactResourceTest extends EntityTestCase {
public void testPersistence() { public void testPersistence() {
assertThat( assertThat(
loadByForeignKey(ContactResource.class, contactResource.getForeignKey(), clock.nowUtc())) loadByForeignKey(ContactResource.class, contactResource.getForeignKey(), clock.nowUtc()))
.isEqualTo(contactResource); .hasValue(contactResource);
} }
@Test @Test

View file

@ -15,6 +15,7 @@
package google.registry.model.domain; package google.registry.model.domain;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EppResourceUtils.loadDomainApplication; import static google.registry.model.EppResourceUtils.loadDomainApplication;
import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps; import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
@ -88,7 +89,7 @@ public class DomainApplicationTest extends EntityTestCase {
@Test @Test
public void testPersistence() { public void testPersistence() {
assertThat(loadDomainApplication(domainApplication.getForeignKey(), clock.nowUtc())) assertThat(loadDomainApplication(domainApplication.getForeignKey(), clock.nowUtc()))
.isEqualTo(domainApplication); .hasValue(domainApplication);
} }
@Test @Test
@ -121,7 +122,6 @@ public class DomainApplicationTest extends EntityTestCase {
@Test @Test
public void testEmptySetsAndArraysBecomeNull() { public void testEmptySetsAndArraysBecomeNull() {
assertThat(emptyBuilder().setNameservers(null).build().nsHosts).isNull();
assertThat(emptyBuilder().setNameservers(ImmutableSet.of()).build().nsHosts).isNull(); assertThat(emptyBuilder().setNameservers(ImmutableSet.of()).build().nsHosts).isNull();
assertThat( assertThat(
emptyBuilder() emptyBuilder()

View file

@ -17,6 +17,7 @@ package google.registry.model.domain;
import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps; import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
@ -151,7 +152,7 @@ public class DomainResourceTest extends EntityTestCase {
@Test @Test
public void testPersistence() { public void testPersistence() {
assertThat(loadByForeignKey(DomainResource.class, domain.getForeignKey(), clock.nowUtc())) assertThat(loadByForeignKey(DomainResource.class, domain.getForeignKey(), clock.nowUtc()))
.isEqualTo(domain); .hasValue(domain);
} }
@Test @Test
@ -187,7 +188,12 @@ public class DomainResourceTest extends EntityTestCase {
@Test @Test
public void testEmptySetsAndArraysBecomeNull() { public void testEmptySetsAndArraysBecomeNull() {
assertThat(newDomainResource("example.com").asBuilder().setNameservers(null).build().nsHosts) assertThat(
newDomainResource("example.com")
.asBuilder()
.setNameservers(ImmutableSet.of())
.build()
.nsHosts)
.isNull(); .isNull();
assertThat( assertThat(
newDomainResource("example.com") newDomainResource("example.com")

View file

@ -15,6 +15,7 @@
package google.registry.model.host; package google.registry.model.host;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps; import static google.registry.testing.DatastoreHelper.cloneAndSetAutoTimestamps;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
@ -86,9 +87,8 @@ public class HostResourceTest extends EntityTestCase {
@Test @Test
public void testPersistence() { public void testPersistence() {
assertThat(loadByForeignKey( assertThat(loadByForeignKey(HostResource.class, host.getForeignKey(), clock.nowUtc()))
HostResource.class, host.getForeignKey(), clock.nowUtc())) .hasValue(host);
.isEqualTo(host);
} }
@Test @Test

View file

@ -15,6 +15,8 @@
package google.registry.model.index; package google.registry.model.index;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.deleteResource;
@ -29,7 +31,6 @@ import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.model.EntityTestCase; import google.registry.model.EntityTestCase;
import google.registry.model.EppResourceUtils;
import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.model.index.ForeignKeyIndex.ForeignKeyHostIndex; import google.registry.model.index.ForeignKeyIndex.ForeignKeyHostIndex;
@ -180,10 +181,8 @@ public class ForeignKeyIndexTest extends EntityTestCase {
clock.advanceOneMilli(); clock.advanceOneMilli();
ForeignKeyIndex<HostResource> newFki = loadHostFki("ns1.example.com"); ForeignKeyIndex<HostResource> newFki = loadHostFki("ns1.example.com");
assertThat(newFki).isNotEqualTo(originalFki); assertThat(newFki).isNotEqualTo(originalFki);
assertThat( assertThat(loadByForeignKey(HostResource.class, "ns1.example.com", clock.nowUtc()))
EppResourceUtils.loadByForeignKey( .hasValue(modifiedHost);
HostResource.class, "ns1.example.com", clock.nowUtc()))
.isEqualTo(modifiedHost);
assertThat( assertThat(
ForeignKeyIndex.loadCached( ForeignKeyIndex.loadCached(
HostResource.class, ImmutableList.of("ns1.example.com"), clock.nowUtc())) HostResource.class, ImmutableList.of("ns1.example.com"), clock.nowUtc()))

View file

@ -141,7 +141,8 @@ public class EppLifecycleToolsTest extends EppTestCase {
DateTime createTime = DateTime.parse("2000-06-01T00:02:00Z"); DateTime createTime = DateTime.parse("2000-06-01T00:02:00Z");
DomainResource domain = DomainResource domain =
loadByForeignKey( loadByForeignKey(
DomainResource.class, "example.tld", DateTime.parse("2003-06-02T00:02:00Z")); DomainResource.class, "example.tld", DateTime.parse("2003-06-02T00:02:00Z"))
.get();
BillingEvent.OneTime renewBillingEvent = BillingEvent.OneTime renewBillingEvent =
new BillingEvent.OneTime.Builder() new BillingEvent.OneTime.Builder()
.setReason(Reason.RENEW) .setReason(Reason.RENEW)

View file

@ -196,7 +196,7 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
@Test @Test
public void testSuccess_skipDomainsWithoutNameservers() throws Exception { public void testSuccess_skipDomainsWithoutNameservers() throws Exception {
persistResource(domain1.asBuilder().setNameservers(null).build()); persistResource(domain1.asBuilder().setNameservers(ImmutableSet.of()).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c"); runCommand("--output=" + output, "--tld=xn--q9jyb4c");
assertThat(getOutputAsJson()) assertThat(getOutputAsJson())
.isEqualTo(ImmutableList.of(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT)); .isEqualTo(ImmutableList.of(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT));

View file

@ -82,7 +82,7 @@ public class LockDomainCommandTest extends EppToolCommandTestCase<LockDomainComm
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> runCommandForced("--client=NewRegistrar", "missing.tld")); () -> runCommandForced("--client=NewRegistrar", "missing.tld"));
assertThat(e).hasMessageThat().isEqualTo("Domain 'missing.tld' does not exist"); assertThat(e).hasMessageThat().isEqualTo("Domain 'missing.tld' does not exist or is deleted");
} }
@Test @Test

View file

@ -94,7 +94,7 @@ public class UnlockDomainCommandTest extends EppToolCommandTestCase<UnlockDomain
assertThrows( assertThrows(
IllegalArgumentException.class, IllegalArgumentException.class,
() -> runCommandForced("--client=NewRegistrar", "missing.tld")); () -> runCommandForced("--client=NewRegistrar", "missing.tld"));
assertThat(e).hasMessageThat().isEqualTo("Domain 'missing.tld' does not exist"); assertThat(e).hasMessageThat().isEqualTo("Domain 'missing.tld' does not exist or is deleted");
} }
@Test @Test

View file

@ -79,10 +79,12 @@ public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainComma
clock.advanceOneMilli(); clock.advanceOneMilli();
assertThat( assertThat(
loadByForeignKey(DomainResource.class, "foo.tld", clock.nowUtc()) loadByForeignKey(DomainResource.class, "foo.tld", clock.nowUtc())
.get()
.getRegistrationExpirationTime()) .getRegistrationExpirationTime())
.isEqualTo(DateTime.parse("2019-12-06T13:55:01.001Z")); .isEqualTo(DateTime.parse("2019-12-06T13:55:01.001Z"));
assertThat( assertThat(
loadByForeignKey(DomainResource.class, "bar.tld", clock.nowUtc()) loadByForeignKey(DomainResource.class, "bar.tld", clock.nowUtc())
.get()
.getRegistrationExpirationTime()) .getRegistrationExpirationTime())
.isEqualTo(DateTime.parse("2018-12-06T13:55:01.002Z")); .isEqualTo(DateTime.parse("2018-12-06T13:55:01.002Z"));
assertInStdout("Successfully unrenewed all domains."); assertInStdout("Successfully unrenewed all domains.");
@ -99,7 +101,7 @@ public class UnrenewDomainCommandTest extends CommandTestCase<UnrenewDomainComma
runCommandForced("-p", "2", "foo.tld"); runCommandForced("-p", "2", "foo.tld");
DateTime unrenewTime = clock.nowUtc(); DateTime unrenewTime = clock.nowUtc();
clock.advanceOneMilli(); clock.advanceOneMilli();
DomainResource domain = loadByForeignKey(DomainResource.class, "foo.tld", clock.nowUtc()); DomainResource domain = loadByForeignKey(DomainResource.class, "foo.tld", clock.nowUtc()).get();
assertAboutHistoryEntries() assertAboutHistoryEntries()
.that(getOnlyHistoryEntryOfType(domain, SYNTHETIC)) .that(getOnlyHistoryEntryOfType(domain, SYNTHETIC))