mirror of
https://github.com/google/nomulus.git
synced 2025-05-16 09:27:16 +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
|
@ -22,7 +22,6 @@ import com.google.common.truth.SimpleSubjectBuilder;
|
|||
import google.registry.model.contact.ContactResource;
|
||||
import google.registry.model.contact.PostalInfo;
|
||||
import google.registry.model.eppcommon.AuthInfo;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import google.registry.testing.TruthChainer.And;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
|
@ -126,42 +125,6 @@ public final class ContactResourceSubject
|
|||
return hasValue(pw, authInfo == null ? null : authInfo.getPw().getValue(), "has auth info pw");
|
||||
}
|
||||
|
||||
public And<ContactResourceSubject> hasTransferStatus(TransferStatus transferStatus) {
|
||||
return hasValue(
|
||||
transferStatus,
|
||||
actual().getTransferData().getTransferStatus(),
|
||||
"has transferStatus");
|
||||
}
|
||||
|
||||
public And<ContactResourceSubject> hasTransferRequestClientTrid(String clTrid) {
|
||||
return hasValue(
|
||||
clTrid,
|
||||
actual().getTransferData().getTransferRequestTrid().getClientTransactionId(),
|
||||
"has trid");
|
||||
}
|
||||
|
||||
public And<ContactResourceSubject> hasPendingTransferExpirationTime(
|
||||
DateTime pendingTransferExpirationTime) {
|
||||
return hasValue(
|
||||
pendingTransferExpirationTime,
|
||||
actual().getTransferData().getPendingTransferExpirationTime(),
|
||||
"has pendingTransferExpirationTime");
|
||||
}
|
||||
|
||||
public And<ContactResourceSubject> hasTransferGainingClientId(String gainingClientId) {
|
||||
return hasValue(
|
||||
gainingClientId,
|
||||
actual().getTransferData().getGainingClientId(),
|
||||
"has transfer ga");
|
||||
}
|
||||
|
||||
public And<ContactResourceSubject> hasTransferLosingClientId(String losingClientId) {
|
||||
return hasValue(
|
||||
losingClientId,
|
||||
actual().getTransferData().getLosingClientId(),
|
||||
"has transfer losingClientId");
|
||||
}
|
||||
|
||||
public And<ContactResourceSubject> hasLastTransferTime(DateTime lastTransferTime) {
|
||||
return hasValue(
|
||||
lastTransferTime,
|
||||
|
|
|
@ -99,6 +99,7 @@ import google.registry.model.transfer.TransferData.Builder;
|
|||
import google.registry.model.transfer.TransferData.TransferServerApproveEntity;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import google.registry.tmch.LordnTask;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -645,19 +646,27 @@ public class DatastoreHelper {
|
|||
ofy().load().type(BillingEvent.Cancellation.class).ancestor(resource));
|
||||
}
|
||||
|
||||
/** Assert that the actual billing event matches the expected one, ignoring IDs. */
|
||||
public static void assertBillingEventsEqual(BillingEvent actual, BillingEvent expected) {
|
||||
assertThat(BILLING_EVENT_ID_STRIPPER.apply(actual))
|
||||
.isEqualTo(BILLING_EVENT_ID_STRIPPER.apply(expected));
|
||||
}
|
||||
|
||||
/** Assert that the actual billing events match the expected ones, ignoring IDs and order. */
|
||||
public static void assertBillingEventsEqual(
|
||||
Iterable<BillingEvent> actual, Iterable<BillingEvent> expected) {
|
||||
assertThat(Iterables.transform(actual, BILLING_EVENT_ID_STRIPPER))
|
||||
.containsExactlyElementsIn(Iterables.transform(expected, BILLING_EVENT_ID_STRIPPER));
|
||||
}
|
||||
|
||||
/** Assert that the expected billing events are exactly the ones found in the fake Datastore. */
|
||||
public static void assertBillingEvents(BillingEvent... expected) throws Exception {
|
||||
assertThat(FluentIterable.from(getBillingEvents()).transform(BILLING_EVENT_ID_STRIPPER))
|
||||
.containsExactlyElementsIn(
|
||||
FluentIterable.from(expected).transform(BILLING_EVENT_ID_STRIPPER));
|
||||
assertBillingEventsEqual(getBillingEvents(), Arrays.asList(expected));
|
||||
}
|
||||
|
||||
/** Assert that the expected billing events set is exactly the one found in the fake Datastore. */
|
||||
public static void assertBillingEvents(ImmutableSet<BillingEvent> expected) throws Exception {
|
||||
assertThat(FluentIterable.from(getBillingEvents()).transform(BILLING_EVENT_ID_STRIPPER))
|
||||
.containsExactlyElementsIn(
|
||||
FluentIterable.from(expected.asList()).transform(BILLING_EVENT_ID_STRIPPER));
|
||||
assertBillingEventsEqual(getBillingEvents(), expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -684,6 +693,19 @@ public class DatastoreHelper {
|
|||
return billingEvent.asBuilder().setId(1L).build();
|
||||
}};
|
||||
|
||||
/** Assert that the actual poll message matches the expected one, ignoring IDs. */
|
||||
public static void assertPollMessagesEqual(PollMessage actual, PollMessage expected) {
|
||||
assertThat(POLL_MESSAGE_ID_STRIPPER.apply(actual))
|
||||
.isEqualTo(POLL_MESSAGE_ID_STRIPPER.apply(expected));
|
||||
}
|
||||
|
||||
/** Assert that the actual poll messages match the expected ones, ignoring IDs and order. */
|
||||
public static void assertPollMessagesEqual(
|
||||
Iterable<PollMessage> actual, Iterable<PollMessage> expected) {
|
||||
assertThat(Iterables.transform(actual, POLL_MESSAGE_ID_STRIPPER))
|
||||
.containsExactlyElementsIn(Iterables.transform(expected, POLL_MESSAGE_ID_STRIPPER));
|
||||
}
|
||||
|
||||
public static void assertPollMessagesForResource(EppResource resource, PollMessage... expected)
|
||||
throws Exception {
|
||||
assertThat(FluentIterable.from(getPollMessages(resource)).transform(POLL_MESSAGE_ID_STRIPPER))
|
||||
|
|
|
@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertAbout;
|
|||
import com.google.common.truth.FailureStrategy;
|
||||
import com.google.common.truth.SimpleSubjectBuilder;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import google.registry.testing.TruthChainer.And;
|
||||
import java.util.Objects;
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -33,42 +32,6 @@ public final class DomainResourceSubject
|
|||
private static class SubjectFactory
|
||||
extends ReflectiveSubjectFactory<DomainResource, DomainResourceSubject>{}
|
||||
|
||||
public And<DomainResourceSubject> hasTransferStatus(TransferStatus transferStatus) {
|
||||
return hasValue(
|
||||
transferStatus,
|
||||
actual().getTransferData().getTransferStatus(),
|
||||
"has transferStatus");
|
||||
}
|
||||
|
||||
public And<DomainResourceSubject> hasTransferRequestClientTrid(String clTrid) {
|
||||
return hasValue(
|
||||
clTrid,
|
||||
actual().getTransferData().getTransferRequestTrid().getClientTransactionId(),
|
||||
"has trid");
|
||||
}
|
||||
|
||||
public And<DomainResourceSubject> hasPendingTransferExpirationTime(
|
||||
DateTime pendingTransferExpirationTime) {
|
||||
return hasValue(
|
||||
pendingTransferExpirationTime,
|
||||
actual().getTransferData().getPendingTransferExpirationTime(),
|
||||
"has pendingTransferExpirationTime");
|
||||
}
|
||||
|
||||
public And<DomainResourceSubject> hasTransferGainingClientId(String gainingClientId) {
|
||||
return hasValue(
|
||||
gainingClientId,
|
||||
actual().getTransferData().getGainingClientId(),
|
||||
"has transfer ga");
|
||||
}
|
||||
|
||||
public And<DomainResourceSubject> hasTransferLosingClientId(String losingClientId) {
|
||||
return hasValue(
|
||||
losingClientId,
|
||||
actual().getTransferData().getLosingClientId(),
|
||||
"has transfer losingClientId");
|
||||
}
|
||||
|
||||
public And<DomainResourceSubject> hasRegistrationExpirationTime(DateTime expiration) {
|
||||
if (!Objects.equals(actual().getRegistrationExpirationTime(), expiration)) {
|
||||
failWithBadResults(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue