mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 09:57:17 +02:00
Change transfer flow tests to assert on entire TransferData contents
This CL changes the domain and contact transfer flows to check the entire TransferData on the post-transfer resource, rather than just spot-checking certain fields. This approach provides much better code coverage - in particular, it checks that the non-request flows (approve, cancel, reject) don't modify the fields that they shouldn't be modifying, and that they do actually clear out the transfer server-approve entities fields written by the transfer request flow. It's slightly orthogonal, but I also added testing that the server-approve entities fields are actually set in the request flows, which was previously untested. This is pre-work for introducing an exDate-storing field into TransferData, by making it easier to test everywhere that exDate is set *and* unset only in the correct places. As part of this CL, I've introduced a TransferData.copyConstantFieldsToBuilder() method that is like asBuilder() but instead of copying all the fields to the new builder, it only copies the logically constant ones: losing/gaining client IDs, the request time and TRID, and transferPeriod. This is useful both in tests but is also used in the resolvingPendingTransfer() helper that centralizes the core transfer resolution logic (as of [] That method has its own tests, and in the process I removed a bunch of crufty defunct TransferData tests. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=171053454
This commit is contained in:
parent
3584bbde53
commit
7e68ffa16a
17 changed files with 363 additions and 297 deletions
|
@ -14,15 +14,23 @@
|
|||
|
||||
package google.registry.flows.contact;
|
||||
|
||||
import static com.google.common.base.Predicates.equalTo;
|
||||
import static com.google.common.base.Predicates.not;
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.config.RegistryConfig.getContactAutomaticTransferLength;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
|
||||
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
|
||||
import static google.registry.testing.DatastoreHelper.assertPollMessagesEqual;
|
||||
import static google.registry.testing.DatastoreHelper.deleteResource;
|
||||
import static google.registry.testing.DatastoreHelper.getPollMessages;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
|
||||
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
|
||||
import google.registry.flows.exceptions.AlreadyPendingTransferException;
|
||||
|
@ -31,9 +39,14 @@ import google.registry.flows.exceptions.ObjectAlreadySponsoredException;
|
|||
import google.registry.flows.exceptions.ResourceStatusProhibitsOperationException;
|
||||
import google.registry.model.contact.ContactAuthInfo;
|
||||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.domain.Period;
|
||||
import google.registry.model.domain.Period.Unit;
|
||||
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
|
||||
import google.registry.model.eppcommon.StatusValue;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.transfer.TransferData;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
|
@ -68,22 +81,56 @@ public class ContactTransferRequestFlowTest
|
|||
// Transfer should have been requested. Verify correct fields were set.
|
||||
contact = reloadResourceByForeignKey();
|
||||
assertAboutContacts().that(contact)
|
||||
.hasTransferStatus(TransferStatus.PENDING).and()
|
||||
.hasTransferGainingClientId("NewRegistrar").and()
|
||||
.hasTransferLosingClientId("TheRegistrar").and()
|
||||
.hasTransferRequestClientTrid(getClientTrid()).and()
|
||||
.hasCurrentSponsorClientId("TheRegistrar").and()
|
||||
.hasPendingTransferExpirationTime(afterTransfer).and()
|
||||
.hasOnlyOneHistoryEntryWhich()
|
||||
.hasType(HistoryEntry.Type.CONTACT_TRANSFER_REQUEST);
|
||||
Trid expectedTrid =
|
||||
Trid.create(
|
||||
getClientTrid(),
|
||||
contact.getTransferData().getTransferRequestTrid().getServerTransactionId());
|
||||
assertThat(contact.getTransferData())
|
||||
.isEqualTo(
|
||||
new TransferData.Builder()
|
||||
.setTransferRequestTrid(expectedTrid)
|
||||
.setTransferRequestTime(clock.nowUtc())
|
||||
.setGainingClientId("NewRegistrar")
|
||||
.setLosingClientId("TheRegistrar")
|
||||
// Period is meaningless for contact transfers, but this is the default.
|
||||
.setTransferPeriod(Period.create(1, Unit.YEARS))
|
||||
.setTransferStatus(TransferStatus.PENDING)
|
||||
.setPendingTransferExpirationTime(afterTransfer)
|
||||
// Make the server-approve entities field a no-op comparison; it's easier to
|
||||
// do this comparison separately below.
|
||||
.setServerApproveEntities(contact.getTransferData().getServerApproveEntities())
|
||||
.build());
|
||||
assertNoBillingEvents();
|
||||
assertThat(getPollMessages("TheRegistrar", clock.nowUtc())).hasSize(1);
|
||||
PollMessage losingRequestMessage =
|
||||
getOnlyElement(getPollMessages("TheRegistrar", clock.nowUtc()));
|
||||
|
||||
// If we fast forward AUTOMATIC_TRANSFER_DAYS the transfer should have happened.
|
||||
assertAboutContacts().that(contact.cloneProjectedAtTime(afterTransfer))
|
||||
.hasCurrentSponsorClientId("NewRegistrar");
|
||||
assertThat(getPollMessages("NewRegistrar", afterTransfer)).hasSize(1);
|
||||
assertThat(getPollMessages("TheRegistrar", afterTransfer)).hasSize(2);
|
||||
PollMessage gainingApproveMessage =
|
||||
getOnlyElement(getPollMessages("NewRegistrar", afterTransfer));
|
||||
PollMessage losingApproveMessage =
|
||||
getOnlyElement(
|
||||
Iterables.filter(
|
||||
getPollMessages("TheRegistrar", afterTransfer),
|
||||
not(equalTo(losingRequestMessage))));
|
||||
|
||||
// Check for TransferData server-approve entities containing what we expect: only
|
||||
// poll messages, the approval notice ones for gaining and losing registrars.
|
||||
assertPollMessagesEqual(
|
||||
Iterables.filter(
|
||||
ofy().load()
|
||||
// Use toArray() to coerce the type to something keys() will accept.
|
||||
.keys(contact.getTransferData().getServerApproveEntities().toArray(new Key<?>[]{}))
|
||||
.values(),
|
||||
PollMessage.class),
|
||||
ImmutableList.of(gainingApproveMessage, losingApproveMessage));
|
||||
}
|
||||
|
||||
private void doFailingTest(String commandFilename) throws Exception {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue