diff --git a/java/google/registry/flows/ResourceFlowUtils.java b/java/google/registry/flows/ResourceFlowUtils.java
index a26fef231..5bd9cdce4 100644
--- a/java/google/registry/flows/ResourceFlowUtils.java
+++ b/java/google/registry/flows/ResourceFlowUtils.java
@@ -228,11 +228,7 @@ public final class ResourceFlowUtils {
return builder
.removeStatusValue(StatusValue.PENDING_TRANSFER)
.setTransferData(
- resource.getTransferData().asBuilder()
- .setServerApproveEntities(null)
- .setServerApproveBillingEvent(null)
- .setServerApproveAutorenewEvent(null)
- .setServerApproveAutorenewPollMessage(null)
+ resource.getTransferData().copyConstantFieldsToBuilder()
.setTransferStatus(transferStatus)
.setPendingTransferExpirationTime(checkNotNull(now))
.build());
diff --git a/java/google/registry/model/transfer/TransferData.java b/java/google/registry/model/transfer/TransferData.java
index cc1fd806a..97e75df71 100644
--- a/java/google/registry/model/transfer/TransferData.java
+++ b/java/google/registry/model/transfer/TransferData.java
@@ -120,6 +120,28 @@ public class TransferData extends BaseTransferObject implements Buildable {
return new Builder(clone(this));
}
+ /**
+ * Returns a fresh Builder populated only with the constant fields of this TransferData, i.e.
+ * those that are fixed and unchanging throughout the transfer process.
+ *
+ *
These fields are:
+ *
+ * - transferRequestTrid
+ *
- transferRequestTime
+ *
- gainingClientId
+ *
- losingClientId
+ *
- transferPeriod
+ *
+ */
+ public Builder copyConstantFieldsToBuilder() {
+ return new Builder()
+ .setTransferRequestTrid(this.transferRequestTrid)
+ .setTransferRequestTime(this.transferRequestTime)
+ .setGainingClientId(this.gainingClientId)
+ .setLosingClientId(this.losingClientId)
+ .setTransferPeriod(this.transferPeriod);
+ }
+
/** Builder for {@link TransferData} because it is immutable. */
public static class Builder extends BaseTransferObject.Builder {
diff --git a/javatests/google/registry/batch/DeleteContactsAndHostsActionTest.java b/javatests/google/registry/batch/DeleteContactsAndHostsActionTest.java
index 5b55bfd5b..37ef608ae 100644
--- a/javatests/google/registry/batch/DeleteContactsAndHostsActionTest.java
+++ b/javatests/google/registry/batch/DeleteContactsAndHostsActionTest.java
@@ -27,7 +27,6 @@ import static google.registry.model.reporting.HistoryEntry.Type.CONTACT_DELETE_F
import static google.registry.model.reporting.HistoryEntry.Type.CONTACT_TRANSFER_REQUEST;
import static google.registry.model.reporting.HistoryEntry.Type.HOST_DELETE;
import static google.registry.model.reporting.HistoryEntry.Type.HOST_DELETE_FAILURE;
-import static google.registry.model.transfer.TransferStatus.SERVER_CANCELLED;
import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld;
@@ -88,6 +87,7 @@ import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.transfer.TransferData;
import google.registry.model.transfer.TransferResponse;
+import google.registry.model.transfer.TransferStatus;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeResponse;
@@ -274,8 +274,14 @@ public class DeleteContactsAndHostsActionTest
assertAboutContacts()
.that(softDeletedContact)
.hasOneHistoryEntryEachOfTypes(CONTACT_TRANSFER_REQUEST, CONTACT_DELETE);
- assertThat(softDeletedContact.getTransferData().getPendingTransferExpirationTime())
- .isEqualTo(softDeletedContact.getDeletionTime());
+ // Check that the transfer data reflects the cancelled transfer as we expect.
+ TransferData oldTransferData = contact.getTransferData();
+ assertThat(softDeletedContact.getTransferData())
+ .isEqualTo(
+ oldTransferData.copyConstantFieldsToBuilder()
+ .setTransferStatus(TransferStatus.SERVER_CANCELLED)
+ .setPendingTransferExpirationTime(softDeletedContact.getDeletionTime())
+ .build());
assertNoBillingEvents();
PollMessage deletePollMessage =
Iterables.getOnlyElement(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1)));
@@ -290,7 +296,7 @@ public class DeleteContactsAndHostsActionTest
FluentIterable.from(gainingPollMessage.getResponseData())
.filter(TransferResponse.class))
.getTransferStatus())
- .isEqualTo(SERVER_CANCELLED);
+ .isEqualTo(TransferStatus.SERVER_CANCELLED);
PendingActionNotificationResponse panData =
getOnlyElement(
FluentIterable.from(gainingPollMessage.getResponseData())
diff --git a/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java
index 851a15762..d41bc6803 100644
--- a/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java
+++ b/javatests/google/registry/flows/contact/ContactTransferApproveFlowTest.java
@@ -36,6 +36,7 @@ import google.registry.model.eppcommon.Trid;
import google.registry.model.poll.PendingActionNotificationResponse;
import google.registry.model.poll.PollMessage;
import google.registry.model.reporting.HistoryEntry;
+import google.registry.model.transfer.TransferData;
import google.registry.model.transfer.TransferResponse;
import google.registry.model.transfer.TransferStatus;
import org.junit.Before;
@@ -64,6 +65,8 @@ public class ContactTransferApproveFlowTest
.hasSize(1);
// Setup done; run the test.
+ contact = reloadResourceByForeignKey();
+ TransferData originalTransferData = contact.getTransferData();
assertTransactionalFlow(true);
runFlowAssertResponse(readFile(expectedXmlFilename));
@@ -72,11 +75,15 @@ public class ContactTransferApproveFlowTest
assertAboutContacts().that(contact)
.hasCurrentSponsorClientId("NewRegistrar").and()
.hasLastTransferTime(clock.nowUtc()).and()
- .hasTransferStatus(TransferStatus.CLIENT_APPROVED).and()
- .hasPendingTransferExpirationTime(clock.nowUtc()).and()
.hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.CONTACT_TRANSFER_REQUEST,
HistoryEntry.Type.CONTACT_TRANSFER_APPROVE);
+ assertThat(contact.getTransferData())
+ .isEqualTo(
+ originalTransferData.copyConstantFieldsToBuilder()
+ .setTransferStatus(TransferStatus.CLIENT_APPROVED)
+ .setPendingTransferExpirationTime(clock.nowUtc())
+ .build());
assertNoBillingEvents();
// The poll message (in the future) to the losing registrar for implicit ack should be gone.
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))).isEmpty();
diff --git a/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java
index 3d3a875ee..57b33d3ca 100644
--- a/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java
+++ b/javatests/google/registry/flows/contact/ContactTransferCancelFlowTest.java
@@ -33,6 +33,7 @@ import google.registry.model.contact.ContactResource;
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
import google.registry.model.poll.PollMessage;
import google.registry.model.reporting.HistoryEntry;
+import google.registry.model.transfer.TransferData;
import google.registry.model.transfer.TransferResponse;
import google.registry.model.transfer.TransferStatus;
import org.junit.Before;
@@ -58,6 +59,8 @@ public class ContactTransferCancelFlowTest
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))).hasSize(1);
// Setup done; run the test.
+ contact = reloadResourceByForeignKey();
+ TransferData originalTransferData = contact.getTransferData();
assertTransactionalFlow(true);
runFlowAssertResponse(readFile(expectedXmlFilename));
@@ -66,11 +69,15 @@ public class ContactTransferCancelFlowTest
assertAboutContacts().that(contact)
.hasCurrentSponsorClientId("TheRegistrar").and()
.hasLastTransferTimeNotEqualTo(clock.nowUtc()).and()
- .hasTransferStatus(TransferStatus.CLIENT_CANCELLED).and()
- .hasPendingTransferExpirationTime(clock.nowUtc()).and()
.hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.CONTACT_TRANSFER_REQUEST,
HistoryEntry.Type.CONTACT_TRANSFER_CANCEL);
+ assertThat(contact.getTransferData())
+ .isEqualTo(
+ originalTransferData.copyConstantFieldsToBuilder()
+ .setTransferStatus(TransferStatus.CLIENT_CANCELLED)
+ .setPendingTransferExpirationTime(clock.nowUtc())
+ .build());
assertNoBillingEvents();
// The poll message (in the future) to the gaining registrar for implicit ack should be gone.
assertThat(getPollMessages("NewRegistrar", clock.nowUtc().plusMonths(1))).isEmpty();
diff --git a/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java
index 8b7158ef4..7213ad424 100644
--- a/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java
+++ b/javatests/google/registry/flows/contact/ContactTransferRejectFlowTest.java
@@ -35,6 +35,7 @@ import google.registry.model.eppcommon.Trid;
import google.registry.model.poll.PendingActionNotificationResponse;
import google.registry.model.poll.PollMessage;
import google.registry.model.reporting.HistoryEntry;
+import google.registry.model.transfer.TransferData;
import google.registry.model.transfer.TransferResponse;
import google.registry.model.transfer.TransferStatus;
import org.junit.Before;
@@ -62,6 +63,8 @@ public class ContactTransferRejectFlowTest
.hasSize(1);
// Setup done; run the test.
+ contact = reloadResourceByForeignKey();
+ TransferData originalTransferData = contact.getTransferData();
assertTransactionalFlow(true);
runFlowAssertResponse(readFile(expectedXmlFilename));
@@ -70,10 +73,15 @@ public class ContactTransferRejectFlowTest
assertAboutContacts().that(contact)
.hasCurrentSponsorClientId("TheRegistrar").and()
.hasLastTransferTimeNotEqualTo(clock.nowUtc()).and()
- .hasTransferStatus(TransferStatus.CLIENT_REJECTED).and()
.hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.CONTACT_TRANSFER_REQUEST,
HistoryEntry.Type.CONTACT_TRANSFER_REJECT);
+ assertThat(contact.getTransferData())
+ .isEqualTo(
+ originalTransferData.copyConstantFieldsToBuilder()
+ .setTransferStatus(TransferStatus.CLIENT_REJECTED)
+ .setPendingTransferExpirationTime(clock.nowUtc())
+ .build());
// The poll message (in the future) to the losing registrar for implicit ack should be gone.
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1)))
.isEmpty();
diff --git a/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java b/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java
index bb1174e31..12b4a9d78 100644
--- a/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java
+++ b/javatests/google/registry/flows/contact/ContactTransferRequestFlowTest.java
@@ -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 {
diff --git a/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java b/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java
index 49207942d..959b1b5fc 100644
--- a/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java
+++ b/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java
@@ -560,13 +560,15 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase originalGracePeriods = domain.getGracePeriods();
+ TransferData originalTransferData = domain.getTransferData();
runFlowAssertResponse(readFile(expectedXmlFilename));
// Transfer should have been cancelled. Verify correct fields were set.
domain = reloadResourceByForeignKey();
- assertTransferFailed(domain, TransferStatus.CLIENT_CANCELLED);
+ assertTransferFailed(domain, TransferStatus.CLIENT_CANCELLED, originalTransferData);
assertAboutDomains().that(domain)
.hasRegistrationExpirationTime(originalExpirationTime).and()
.hasLastTransferTimeNotEqualTo(clock.nowUtc());
diff --git a/javatests/google/registry/flows/domain/DomainTransferFlowTestCase.java b/javatests/google/registry/flows/domain/DomainTransferFlowTestCase.java
index 83aa82a35..5743ab32d 100644
--- a/javatests/google/registry/flows/domain/DomainTransferFlowTestCase.java
+++ b/javatests/google/registry/flows/domain/DomainTransferFlowTestCase.java
@@ -204,17 +204,19 @@ public class DomainTransferFlowTestCase
.build();
}
- protected void assertTransferFailed(DomainResource domain, TransferStatus status) {
+ protected void assertTransferFailed(
+ DomainResource domain, TransferStatus status, TransferData oldTransferData) {
assertAboutDomains().that(domain)
- .hasTransferStatus(status).and()
- .hasPendingTransferExpirationTime(clock.nowUtc()).and()
.doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER).and()
.hasCurrentSponsorClientId("TheRegistrar");
- TransferData transferData = domain.getTransferData();
- assertThat(transferData.getServerApproveBillingEvent()).isNull();
- assertThat(transferData.getServerApproveAutorenewEvent()).isNull();
- assertThat(transferData.getServerApproveAutorenewPollMessage()).isNull();
- assertThat(transferData.getServerApproveEntities()).isEmpty();
+ // The domain TransferData should reflect the failed transfer as we expect, with
+ // all the speculative server-approve fields nulled out.
+ assertThat(domain.getTransferData())
+ .isEqualTo(
+ oldTransferData.copyConstantFieldsToBuilder()
+ .setTransferStatus(status)
+ .setPendingTransferExpirationTime(clock.nowUtc())
+ .build());
}
/** Adds a domain that has a pending transfer on it from TheRegistrar to NewRegistrar. */
diff --git a/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java
index b08b6b570..4c3431818 100644
--- a/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java
+++ b/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java
@@ -51,6 +51,7 @@ import google.registry.model.poll.PollMessage;
import google.registry.model.registry.Registry;
import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.HistoryEntry;
+import google.registry.model.transfer.TransferData;
import google.registry.model.transfer.TransferResponse;
import google.registry.model.transfer.TransferStatus;
import org.joda.time.DateTime;
@@ -89,10 +90,11 @@ public class DomainTransferRejectFlowTest
assertTransactionalFlow(true);
DateTime originalExpirationTime = domain.getRegistrationExpirationTime();
ImmutableSet originalGracePeriods = domain.getGracePeriods();
+ TransferData originalTransferData = domain.getTransferData();
runFlowAssertResponse(readFile(expectedXmlFilename));
// Transfer should have been rejected. Verify correct fields were set.
domain = reloadResourceByForeignKey();
- assertTransferFailed(domain, TransferStatus.CLIENT_REJECTED);
+ assertTransferFailed(domain, TransferStatus.CLIENT_REJECTED, originalTransferData);
assertAboutDomains().that(domain)
.hasRegistrationExpirationTime(originalExpirationTime).and()
.hasLastTransferTimeNotEqualTo(clock.nowUtc()).and()
diff --git a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java
index 1572176ef..13890ce6e 100644
--- a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java
+++ b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java
@@ -20,6 +20,8 @@ import static google.registry.model.reporting.DomainTransactionRecord.Transactio
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_CREATE;
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST;
import static google.registry.testing.DatastoreHelper.assertBillingEvents;
+import static google.registry.testing.DatastoreHelper.assertBillingEventsEqual;
+import static google.registry.testing.DatastoreHelper.assertPollMessagesEqual;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.getOnlyHistoryEntryOfType;
import static google.registry.testing.DatastoreHelper.getOnlyPollMessage;
@@ -39,6 +41,7 @@ import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
@@ -74,11 +77,13 @@ import google.registry.model.domain.Period.Unit;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
import google.registry.model.eppcommon.StatusValue;
+import google.registry.model.eppcommon.Trid;
import google.registry.model.poll.PendingActionNotificationResponse;
import google.registry.model.poll.PollMessage;
import google.registry.model.registry.Registry;
import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.HistoryEntry;
+import google.registry.model.transfer.TransferData;
import google.registry.model.transfer.TransferResponse;
import google.registry.model.transfer.TransferStatus;
import java.util.Map;
@@ -124,33 +129,56 @@ public class DomainTransferRequestFlowTest
}
private void assertTransferRequested(
- DomainResource domain, Optional expectedAutomaticTransferLength) throws Exception {
- DateTime afterAutoAckTime =
- (expectedAutomaticTransferLength.isPresent())
- ? clock.nowUtc().plus(expectedAutomaticTransferLength.get())
- : clock.nowUtc().plus(Registry.get(domain.getTld()).getAutomaticTransferLength());
+ DomainResource domain, DateTime automaticTransferTime, Period expectedPeriod)
+ throws Exception {
assertAboutDomains().that(domain)
- .hasTransferStatus(TransferStatus.PENDING).and()
- .hasTransferGainingClientId("NewRegistrar").and()
- .hasTransferLosingClientId("TheRegistrar").and()
- .hasTransferRequestClientTrid(getClientTrid()).and()
.hasCurrentSponsorClientId("TheRegistrar").and()
- .hasPendingTransferExpirationTime(afterAutoAckTime).and()
.hasStatusValue(StatusValue.PENDING_TRANSFER);
+ Trid expectedTrid =
+ Trid.create(
+ getClientTrid(),
+ domain.getTransferData().getTransferRequestTrid().getServerTransactionId());
+ assertThat(domain.getTransferData())
+ .isEqualTo(
+ // Compare against only the following fields by rebuilding the existing TransferData.
+ // Equivalent to assertThat(transferData.getGainingClientId()).isEqualTo("NewReg")
+ // and similar individual assertions, but produces a nicer error message this way.
+ domain.getTransferData().asBuilder()
+ .setGainingClientId("NewRegistrar")
+ .setLosingClientId("TheRegistrar")
+ .setTransferRequestTrid(expectedTrid)
+ .setTransferRequestTime(clock.nowUtc())
+ .setTransferPeriod(expectedPeriod)
+ .setTransferStatus(TransferStatus.PENDING)
+ .setPendingTransferExpirationTime(automaticTransferTime)
+ // Don't compare the server-approve entity fields; they're hard to reconstruct
+ // and logic later will check them.
+ .build());
}
private void assertTransferApproved(
- DomainResource domain, Optional expectedAutomaticTransferLength) {
- DateTime afterAutoAckTime =
- (expectedAutomaticTransferLength.isPresent())
- ? clock.nowUtc().plus(expectedAutomaticTransferLength.get())
- : clock.nowUtc().plus(Registry.get(domain.getTld()).getAutomaticTransferLength());
+ DomainResource domain, DateTime automaticTransferTime, Period expectedPeriod)
+ throws Exception {
assertAboutDomains().that(domain)
- .hasTransferStatus(TransferStatus.SERVER_APPROVED).and()
.hasCurrentSponsorClientId("NewRegistrar").and()
- .hasLastTransferTime(afterAutoAckTime).and()
- .hasPendingTransferExpirationTime(afterAutoAckTime).and()
+ .hasLastTransferTime(automaticTransferTime).and()
.doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER);
+ Trid expectedTrid =
+ Trid.create(
+ getClientTrid(),
+ domain.getTransferData().getTransferRequestTrid().getServerTransactionId());
+ assertThat(domain.getTransferData())
+ .isEqualTo(
+ new TransferData.Builder()
+ .setGainingClientId("NewRegistrar")
+ .setLosingClientId("TheRegistrar")
+ .setTransferRequestTrid(expectedTrid)
+ .setTransferRequestTime(clock.nowUtc())
+ .setTransferPeriod(expectedPeriod)
+ .setTransferStatus(TransferStatus.SERVER_APPROVED)
+ .setPendingTransferExpirationTime(automaticTransferTime)
+ // Server-approve entity fields should all be nulled out.
+ .build());
}
/**
@@ -177,20 +205,22 @@ public class DomainTransferRequestFlowTest
// Setup done; run the test.
assertTransactionalFlow(true);
runFlowAssertResponse(readFile(expectedXmlFilename, substitutions));
- // Transfer should have been requested. Verify correct fields were set.
+ // Transfer should have been requested.
domain = reloadResourceByForeignKey();
+ // Verify that HistoryEntry was created.
+ assertAboutDomains().that(domain)
+ .hasOneHistoryEntryEachOfTypes(DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST);
final HistoryEntry historyEntryTransferRequest =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST);
- subordinateHost = reloadResourceAndCloneAtTime(subordinateHost, clock.nowUtc());
- assertTransferRequested(domain, Optional.absent());
- assertAboutDomains().that(domain)
- .hasPendingTransferExpirationTime(implicitTransferTime).and()
- .hasOneHistoryEntryEachOfTypes(DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST);
assertAboutHistoryEntries()
.that(historyEntryTransferRequest)
.hasPeriodYears(1)
.and()
.hasOtherClientId("TheRegistrar");
+ // Verify correct fields were set.
+ assertTransferRequested(domain, implicitTransferTime, Period.create(1, Unit.YEARS));
+
+ subordinateHost = reloadResourceAndCloneAtTime(subordinateHost, clock.nowUtc());
assertAboutHosts().that(subordinateHost).hasNoHistoryEntries();
assertHistoryEntriesContainBillingEventsAndGracePeriods(
@@ -201,11 +231,9 @@ public class DomainTransferRequestFlowTest
/* expectTransferBillingEvent = */ true,
extraExpectedBillingEvents);
- assertPollMessagesEmitted(
- expectedExpirationTime, implicitTransferTime, Optional.absent());
-
+ assertPollMessagesEmitted(expectedExpirationTime, implicitTransferTime);
assertAboutDomainAfterAutomaticTransfer(
- expectedExpirationTime, implicitTransferTime, Optional.absent());
+ expectedExpirationTime, implicitTransferTime, Period.create(1, Unit.YEARS));
}
private void assertHistoryEntriesContainBillingEventsAndGracePeriods(
@@ -220,6 +248,8 @@ public class DomainTransferRequestFlowTest
final HistoryEntry historyEntryTransferRequest =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST);
+ // Construct the billing events we expect to exist, starting with the (optional) billing
+ // event for the transfer itself.
Optional optionalTransferBillingEvent;
if (expectTransferBillingEvent) {
// For normal transfers, a BillingEvent should be created AUTOMATIC_TRANSFER_DAYS in the
@@ -241,28 +271,57 @@ public class DomainTransferRequestFlowTest
// Superuser transfers with no bundled renewal have no transfer billing event.
optionalTransferBillingEvent = Optional.absent();
}
- // Assert that the billing events we expect are present - any extra cancellations, then the
- // transfer billing event if there is one, plus two autorenew billing events, one for the losing
- // client ending at the transfer time, and one for the gaining client starting at the domain's
- // post-transfer expiration time.
- assertBillingEvents(FluentIterable.from(extraExpectedBillingEvents)
- .transform(new Function() {
- @Override
- public BillingEvent apply(Builder builder) {
- return builder.setParent(historyEntryTransferRequest).build();
- }})
+ // Construct the autorenew events for the losing/existing client and the gaining one. Note that
+ // all of the other transfer flow tests happen on day 3 of the transfer, but the initial
+ // request by definition takes place on day 1, so we need to edit the times in the
+ // autorenew events from the base test case.
+ BillingEvent.Recurring losingClientAutorenew =
+ getLosingClientAutorenewEvent().asBuilder()
+ .setRecurrenceEndTime(implicitTransferTime)
+ .build();
+ BillingEvent.Recurring gainingClientAutorenew =
+ getGainingClientAutorenewEvent().asBuilder()
+ .setEventTime(expectedExpirationTime)
+ .build();
+ // Construct extra billing events expected by the specific test.
+ ImmutableList extraBillingEvents =
+ FluentIterable.from(extraExpectedBillingEvents)
+ .transform(
+ new Function() {
+ @Override
+ public BillingEvent apply(Builder builder) {
+ return builder.setParent(historyEntryTransferRequest).build();
+ }})
+ .toList();
+ // Assert that the billing events we constructed above actually exist in datastore.
+ assertBillingEvents(FluentIterable.from(extraBillingEvents)
.append(optionalTransferBillingEvent.asSet())
- .append(
- // All of the other transfer flow tests happen on day 3 of the transfer, but the initial
- // request by definition takes place on day 1, so we need to edit the times in the
- // autorenew events from the base test case.
- getLosingClientAutorenewEvent().asBuilder()
- .setRecurrenceEndTime(implicitTransferTime)
- .build(),
- getGainingClientAutorenewEvent().asBuilder()
- .setEventTime(expectedExpirationTime)
- .build())
+ .append(losingClientAutorenew)
+ .append(gainingClientAutorenew)
.toArray(BillingEvent.class));
+ // Assert that the domain's TransferData server-approve billing events match the above.
+ if (expectTransferBillingEvent) {
+ assertBillingEventsEqual(
+ ofy().load().key(domain.getTransferData().getServerApproveBillingEvent()).now(),
+ optionalTransferBillingEvent.get());
+ } else {
+ assertThat(domain.getTransferData().getServerApproveBillingEvent()).isNull();
+ }
+ assertBillingEventsEqual(
+ ofy().load().key(domain.getTransferData().getServerApproveAutorenewEvent()).now(),
+ gainingClientAutorenew);
+ // Assert that the full set of server-approve billing events is exactly the extra ones plus
+ // the transfer billing event (if present) and the gaining client autorenew.
+ assertBillingEventsEqual(
+ Iterables.filter(
+ ofy().load()
+ // Use toArray() to coerce the type to something keys() will accept.
+ .keys(domain.getTransferData().getServerApproveEntities().toArray(new Key>[]{}))
+ .values(),
+ BillingEvent.class),
+ FluentIterable.from(extraBillingEvents)
+ .append(optionalTransferBillingEvent.asSet())
+ .append(gainingClientAutorenew));
// The domain's autorenew billing event should still point to the losing client's event.
BillingEvent.Recurring domainAutorenewEvent =
ofy().load().key(domain.getAutorenewBillingEvent()).now();
@@ -291,18 +350,12 @@ public class DomainTransferRequestFlowTest
}
private void assertPollMessagesEmitted(
- DateTime expectedExpirationTime,
- DateTime implicitTransferTime,
- Optional expectedAutomaticTransferLength) {
+ DateTime expectedExpirationTime, DateTime implicitTransferTime) {
// Assert that there exists a poll message to notify the losing registrar that a transfer was
- // requested. If the expected automatic transfer length is zero, then also expect a server
- // approved poll message.
+ // requested. If the implicit transfer time is now (i.e. the automatic transfer length is zero)
+ // then also expect a server approved poll message.
assertThat(getPollMessages("TheRegistrar", clock.nowUtc()))
- .hasSize(
- (expectedAutomaticTransferLength.isPresent()
- && expectedAutomaticTransferLength.get().equals(Duration.ZERO))
- ? 2
- : 1);
+ .hasSize(implicitTransferTime.equals(clock.nowUtc()) ? 2 : 1);
// Two poll messages on the gaining registrar's side at the expected expiration time: a
// (OneTime) transfer approved message, and an Autorenew poll message.
@@ -354,15 +407,32 @@ public class DomainTransferRequestFlowTest
.filter(TransferResponse.class))
.getTransferStatus())
.isEqualTo(TransferStatus.SERVER_APPROVED);
+
+ // Assert that the poll messages show up in the TransferData server approve entities.
+ assertPollMessagesEqual(
+ ofy().load().key(domain.getTransferData().getServerApproveAutorenewPollMessage()).now(),
+ autorenewPollMessage);
+ // Assert that the full set of server-approve poll messages is exactly the server approve
+ // OneTime messages to gaining and losing registrars plus the gaining client autorenew.
+ assertPollMessagesEqual(
+ Iterables.filter(
+ ofy().load()
+ // Use toArray() to coerce the type to something keys() will accept.
+ .keys(domain.getTransferData().getServerApproveEntities().toArray(new Key>[]{}))
+ .values(),
+ PollMessage.class),
+ ImmutableList.of(
+ transferApprovedPollMessage,
+ losingTransferApprovedPollMessage,
+ autorenewPollMessage));
}
private void assertAboutDomainAfterAutomaticTransfer(
- DateTime expectedExpirationTime,
- DateTime implicitTransferTime,
- Optional expectedAutomaticTransferLength) {
+ DateTime expectedExpirationTime, DateTime implicitTransferTime, Period expectedPeriod)
+ throws Exception {
Registry registry = Registry.get(domain.getTld());
DomainResource domainAfterAutomaticTransfer = domain.cloneProjectedAtTime(implicitTransferTime);
- assertTransferApproved(domainAfterAutomaticTransfer, expectedAutomaticTransferLength);
+ assertTransferApproved(domainAfterAutomaticTransfer, implicitTransferTime, expectedPeriod);
assertAboutDomains().that(domainAfterAutomaticTransfer)
.hasRegistrationExpirationTime(expectedExpirationTime);
assertThat(ofy().load().key(domainAfterAutomaticTransfer.getAutorenewBillingEvent()).now()
@@ -440,11 +510,8 @@ public class DomainTransferRequestFlowTest
// Transfer should have been requested.
domain = reloadResourceByForeignKey();
}
- // Verify correct fields were set.
- subordinateHost = reloadResourceAndCloneAtTime(subordinateHost, clock.nowUtc());
- assertTransferRequested(domain, Optional.of(expectedAutomaticTransferLength));
+ // Verify that HistoryEntry was created.
assertAboutDomains().that(domain)
- .hasPendingTransferExpirationTime(implicitTransferTime).and()
.hasOneHistoryEntryEachOfTypes(DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST);
final HistoryEntry historyEntryTransferRequest =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST);
@@ -453,6 +520,10 @@ public class DomainTransferRequestFlowTest
.hasPeriodYears(expectedPeriod.getValue())
.and()
.hasOtherClientId("TheRegistrar");
+ // Verify correct fields were set.
+ assertTransferRequested(domain, implicitTransferTime, expectedPeriod);
+
+ subordinateHost = reloadResourceAndCloneAtTime(subordinateHost, clock.nowUtc());
assertAboutHosts().that(subordinateHost).hasNoHistoryEntries();
boolean expectTransferBillingEvent = expectedPeriod.getValue() != 0;
@@ -464,13 +535,9 @@ public class DomainTransferRequestFlowTest
expectTransferBillingEvent,
extraExpectedBillingEvents);
- assertPollMessagesEmitted(
- expectedExpirationTime,
- implicitTransferTime,
- Optional.of(expectedAutomaticTransferLength));
-
+ assertPollMessagesEmitted(expectedExpirationTime, implicitTransferTime);
assertAboutDomainAfterAutomaticTransfer(
- expectedExpirationTime, implicitTransferTime, Optional.of(expectedAutomaticTransferLength));
+ expectedExpirationTime, implicitTransferTime, expectedPeriod);
}
private void runTest(
diff --git a/javatests/google/registry/model/transfer/TransferDataTest.java b/javatests/google/registry/model/transfer/TransferDataTest.java
index 7d286139e..a7ef433f6 100644
--- a/javatests/google/registry/model/transfer/TransferDataTest.java
+++ b/javatests/google/registry/model/transfer/TransferDataTest.java
@@ -15,25 +15,16 @@
package google.registry.model.transfer;
import static com.google.common.truth.Truth.assertThat;
-import static google.registry.model.ofy.ObjectifyService.ofy;
-import static google.registry.testing.DatastoreHelper.createTld;
-import static google.registry.testing.DatastoreHelper.persistResource;
-import static google.registry.util.DateTimeUtils.END_OF_TIME;
-import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.model.billing.BillingEvent;
-import google.registry.model.billing.BillingEvent.Flag;
-import google.registry.model.billing.BillingEvent.Reason;
-import google.registry.model.domain.DomainResource;
+import google.registry.model.domain.Period;
+import google.registry.model.eppcommon.Trid;
import google.registry.model.poll.PollMessage;
-import google.registry.model.reporting.HistoryEntry;
import google.registry.model.transfer.TransferData.TransferServerApproveEntity;
import google.registry.testing.AppEngineRule;
-import google.registry.testing.DatastoreHelper;
-import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
@@ -50,102 +41,53 @@ public class TransferDataTest {
.withDatastore()
.build();
- protected final DateTime now = DateTime.now(UTC);
+ private final DateTime now = DateTime.now(UTC);
- HistoryEntry historyEntry;
- TransferData transferData;
- BillingEvent.OneTime transferBillingEvent;
- BillingEvent.OneTime nonTransferBillingEvent;
- BillingEvent.OneTime otherTransferBillingEvent;
- BillingEvent.Recurring recurringBillingEvent;
+ private Key transferBillingEventKey;
+ private Key otherServerApproveBillingEventKey;
+ private Key recurringBillingEventKey;
+ private Key autorenewPollMessageKey;
+ private Key otherServerApprovePollMessageKey;
@Before
public void setUp() {
- createTld("tld");
- DomainResource domain = DatastoreHelper.persistActiveDomain("tat.tld");
- historyEntry = persistResource(new HistoryEntry.Builder().setParent(domain).build());
- transferBillingEvent = persistResource(makeBillingEvent());
-
- nonTransferBillingEvent = persistResource(
- makeBillingEvent().asBuilder().setReason(Reason.CREATE).build());
-
- otherTransferBillingEvent = persistResource(
- makeBillingEvent().asBuilder().setCost(Money.of(USD, 33)).build());
-
- recurringBillingEvent = persistResource(
- new BillingEvent.Recurring.Builder()
- .setReason(Reason.RENEW)
- .setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
- .setClientId("TheRegistrar")
- .setTargetId("foo.tld")
- .setEventTime(now)
- .setRecurrenceEndTime(END_OF_TIME)
- .setParent(historyEntry)
- .build());
- }
-
- private BillingEvent.OneTime makeBillingEvent() {
- return new BillingEvent.OneTime.Builder()
- .setReason(Reason.TRANSFER)
- .setClientId("TheRegistrar")
- .setTargetId("foo.tld")
- .setEventTime(now)
- .setBillingTime(now.plusDays(5))
- .setCost(Money.of(USD, 42))
- .setPeriodYears(3)
- .setParent(historyEntry)
- .build();
- }
-
- @SafeVarargs
- private static TransferData makeTransferDataWithEntities(
- Key extends TransferServerApproveEntity>... entityKeys) {
- ImmutableSet> entityKeysSet =
- ImmutableSet.copyOf(entityKeys);
- return new TransferData.Builder().setServerApproveEntities(entityKeysSet).build();
+ transferBillingEventKey = Key.create(BillingEvent.OneTime.class, 12345);
+ otherServerApproveBillingEventKey = Key.create(BillingEvent.Cancellation.class, 2468);
+ recurringBillingEventKey = Key.create(BillingEvent.Recurring.class, 13579);
+ autorenewPollMessageKey = Key.create(PollMessage.Autorenew.class, 67890);
+ otherServerApprovePollMessageKey = Key.create(PollMessage.OneTime.class, 314159);
}
@Test
- public void testSuccess_FindBillingEventNoEntities() throws Exception {
- transferData = makeTransferDataWithEntities();
- assertThat(transferData.serverApproveBillingEvent).isNull();
- assertThat(transferData.getServerApproveBillingEvent()).isNull();
- }
-
- @Test
- public void testSuccess_FindBillingEventOtherEntities() throws Exception {
- transferData = makeTransferDataWithEntities(
- Key.create(nonTransferBillingEvent),
- Key.create(recurringBillingEvent),
- Key.create(PollMessage.OneTime.class, 1));
- assertThat(transferData.serverApproveBillingEvent).isNull();
- assertThat(transferData.getServerApproveBillingEvent()).isNull();
- }
-
- @Test
- public void testSuccess_GetStoredBillingEventNoEntities() throws Exception {
- transferData = new TransferData.Builder()
- .setServerApproveBillingEvent(Key.create(transferBillingEvent))
- .build();
- assertThat(ofy().load().key(transferData.serverApproveBillingEvent).now())
- .isEqualTo(transferBillingEvent);
- assertThat(ofy().load().key(transferData.getServerApproveBillingEvent()).now())
- .isEqualTo(transferBillingEvent);
- }
-
- @Test
- public void testSuccess_GetStoredBillingEventMultipleEntities() throws Exception {
- transferData = makeTransferDataWithEntities(
- Key.create(otherTransferBillingEvent),
- Key.create(nonTransferBillingEvent),
- Key.create(recurringBillingEvent),
- Key.create(PollMessage.OneTime.class, 1));
- transferData = transferData.asBuilder()
- .setServerApproveBillingEvent(Key.create(transferBillingEvent))
- .build();
- assertThat(ofy().load().key(transferData.serverApproveBillingEvent).now())
- .isEqualTo(transferBillingEvent);
- assertThat(ofy().load().key(transferData.getServerApproveBillingEvent()).now())
- .isEqualTo(transferBillingEvent);
+ public void test_copyConstantFieldsToBuilder() throws Exception {
+ TransferData constantTransferData =
+ new TransferData.Builder()
+ .setTransferRequestTrid(Trid.create("server-trid", "client-trid"))
+ .setTransferRequestTime(now)
+ .setGainingClientId("NewRegistrar")
+ .setLosingClientId("TheRegistrar")
+ // Test must use a non-1-year period, since that's the default value.
+ .setTransferPeriod(Period.create(5, Period.Unit.YEARS))
+ .build();
+ TransferData fullTransferData =
+ constantTransferData.asBuilder()
+ .setPendingTransferExpirationTime(now)
+ .setTransferStatus(TransferStatus.PENDING)
+ .setServerApproveEntities(
+ ImmutableSet.>of(
+ transferBillingEventKey,
+ otherServerApproveBillingEventKey,
+ recurringBillingEventKey,
+ autorenewPollMessageKey,
+ otherServerApprovePollMessageKey))
+ .setServerApproveBillingEvent(transferBillingEventKey)
+ .setServerApproveAutorenewEvent(recurringBillingEventKey)
+ .setServerApproveAutorenewPollMessage(autorenewPollMessageKey)
+ .build();
+ // asBuilder() copies over all fields
+ assertThat(fullTransferData.asBuilder().build()).isEqualTo(fullTransferData);
+ // copyConstantFieldsToBuilder() copies only constant fields
+ assertThat(fullTransferData.copyConstantFieldsToBuilder().build())
+ .isEqualTo(constantTransferData);
}
}
diff --git a/javatests/google/registry/testing/ContactResourceSubject.java b/javatests/google/registry/testing/ContactResourceSubject.java
index c7371184b..5e9acfec6 100644
--- a/javatests/google/registry/testing/ContactResourceSubject.java
+++ b/javatests/google/registry/testing/ContactResourceSubject.java
@@ -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 hasTransferStatus(TransferStatus transferStatus) {
- return hasValue(
- transferStatus,
- actual().getTransferData().getTransferStatus(),
- "has transferStatus");
- }
-
- public And hasTransferRequestClientTrid(String clTrid) {
- return hasValue(
- clTrid,
- actual().getTransferData().getTransferRequestTrid().getClientTransactionId(),
- "has trid");
- }
-
- public And hasPendingTransferExpirationTime(
- DateTime pendingTransferExpirationTime) {
- return hasValue(
- pendingTransferExpirationTime,
- actual().getTransferData().getPendingTransferExpirationTime(),
- "has pendingTransferExpirationTime");
- }
-
- public And hasTransferGainingClientId(String gainingClientId) {
- return hasValue(
- gainingClientId,
- actual().getTransferData().getGainingClientId(),
- "has transfer ga");
- }
-
- public And hasTransferLosingClientId(String losingClientId) {
- return hasValue(
- losingClientId,
- actual().getTransferData().getLosingClientId(),
- "has transfer losingClientId");
- }
-
public And hasLastTransferTime(DateTime lastTransferTime) {
return hasValue(
lastTransferTime,
diff --git a/javatests/google/registry/testing/DatastoreHelper.java b/javatests/google/registry/testing/DatastoreHelper.java
index df9026060..b8ba6256a 100644
--- a/javatests/google/registry/testing/DatastoreHelper.java
+++ b/javatests/google/registry/testing/DatastoreHelper.java
@@ -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 actual, Iterable 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 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 actual, Iterable 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))
diff --git a/javatests/google/registry/testing/DomainResourceSubject.java b/javatests/google/registry/testing/DomainResourceSubject.java
index 501f520e5..e2fca5afd 100644
--- a/javatests/google/registry/testing/DomainResourceSubject.java
+++ b/javatests/google/registry/testing/DomainResourceSubject.java
@@ -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{}
- public And hasTransferStatus(TransferStatus transferStatus) {
- return hasValue(
- transferStatus,
- actual().getTransferData().getTransferStatus(),
- "has transferStatus");
- }
-
- public And hasTransferRequestClientTrid(String clTrid) {
- return hasValue(
- clTrid,
- actual().getTransferData().getTransferRequestTrid().getClientTransactionId(),
- "has trid");
- }
-
- public And hasPendingTransferExpirationTime(
- DateTime pendingTransferExpirationTime) {
- return hasValue(
- pendingTransferExpirationTime,
- actual().getTransferData().getPendingTransferExpirationTime(),
- "has pendingTransferExpirationTime");
- }
-
- public And hasTransferGainingClientId(String gainingClientId) {
- return hasValue(
- gainingClientId,
- actual().getTransferData().getGainingClientId(),
- "has transfer ga");
- }
-
- public And hasTransferLosingClientId(String losingClientId) {
- return hasValue(
- losingClientId,
- actual().getTransferData().getLosingClientId(),
- "has transfer losingClientId");
- }
-
public And hasRegistrationExpirationTime(DateTime expiration) {
if (!Objects.equals(actual().getRegistrationExpirationTime(), expiration)) {
failWithBadResults(