Re-add EppException marshalling assertions in remaining domain flows

Apologies for the reformatting, but this refactoring is quite rote and it's
definitely a bigger use of total time to perform the reformatting individually
than to simply do it file-wide.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179238504
This commit is contained in:
mcilwain 2017-12-15 14:15:56 -08:00 committed by Ben McIlwain
parent 5e4a6b0235
commit e17109a0eb
6 changed files with 931 additions and 661 deletions

View file

@ -31,8 +31,8 @@ import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
@ -44,6 +44,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException; import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
@ -107,15 +108,19 @@ public class DomainTransferApproveFlowTest
} }
private void assertTransferApproved(DomainResource domain, TransferData oldTransferData) { private void assertTransferApproved(DomainResource domain, TransferData oldTransferData) {
assertAboutDomains().that(domain) assertAboutDomains()
.hasCurrentSponsorClientId("NewRegistrar").and() .that(domain)
.hasLastTransferTime(clock.nowUtc()).and() .hasCurrentSponsorClientId("NewRegistrar")
.and()
.hasLastTransferTime(clock.nowUtc())
.and()
.doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER); .doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER);
// The domain TransferData should reflect the approved transfer as we expect, with // The domain TransferData should reflect the approved transfer as we expect, with
// all the speculative server-approve fields nulled out. // all the speculative server-approve fields nulled out.
assertThat(domain.getTransferData()) assertThat(domain.getTransferData())
.isEqualTo( .isEqualTo(
oldTransferData.copyConstantFieldsToBuilder() oldTransferData
.copyConstantFieldsToBuilder()
.setTransferStatus(TransferStatus.CLIENT_APPROVED) .setTransferStatus(TransferStatus.CLIENT_APPROVED)
.setPendingTransferExpirationTime(clock.nowUtc()) .setPendingTransferExpirationTime(clock.nowUtc())
.setTransferredRegistrationExpirationTime(domain.getRegistrationExpirationTime()) .setTransferredRegistrationExpirationTime(domain.getRegistrationExpirationTime())
@ -139,12 +144,10 @@ public class DomainTransferApproveFlowTest
String expectedXmlFilename, String expectedXmlFilename,
DateTime expectedExpirationTime, DateTime expectedExpirationTime,
int expectedYearsToCharge, int expectedYearsToCharge,
BillingEvent.Cancellation.Builder... expectedCancellationBillingEvents) throws Exception { BillingEvent.Cancellation.Builder... expectedCancellationBillingEvents)
throws Exception {
runSuccessfulFlowWithAssertions( runSuccessfulFlowWithAssertions(
tld, tld, commandFilename, expectedXmlFilename, expectedExpirationTime);
commandFilename,
expectedXmlFilename,
expectedExpirationTime);
assertHistoryEntriesContainBillingEventsAndGracePeriods( assertHistoryEntriesContainBillingEventsAndGracePeriods(
tld, expectedYearsToCharge, expectedCancellationBillingEvents); tld, expectedYearsToCharge, expectedCancellationBillingEvents);
} }
@ -153,7 +156,8 @@ public class DomainTransferApproveFlowTest
String tld, String tld,
String commandFilename, String commandFilename,
String expectedXmlFilename, String expectedXmlFilename,
DateTime expectedExpirationTime) throws Exception { DateTime expectedExpirationTime)
throws Exception {
setEppLoader(commandFilename); setEppLoader(commandFilename);
Registry registry = Registry.get(tld); Registry registry = Registry.get(tld);
domain = reloadResourceByForeignKey(); domain = reloadResourceByForeignKey();
@ -179,8 +183,7 @@ public class DomainTransferApproveFlowTest
DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST, DOMAIN_TRANSFER_APPROVE); DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST, DOMAIN_TRANSFER_APPROVE);
final HistoryEntry historyEntryTransferApproved = final HistoryEntry historyEntryTransferApproved =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_APPROVE); getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_APPROVE);
assertAboutHistoryEntries().that(historyEntryTransferApproved) assertAboutHistoryEntries().that(historyEntryTransferApproved).hasOtherClientId("NewRegistrar");
.hasOtherClientId("NewRegistrar");
assertTransferApproved(domain, originalTransferData); assertTransferApproved(domain, originalTransferData);
assertAboutDomains().that(domain).hasRegistrationExpirationTime(expectedExpirationTime); assertAboutDomains().that(domain).hasRegistrationExpirationTime(expectedExpirationTime);
assertThat(ofy().load().key(domain.getAutorenewBillingEvent()).now().getEventTime()) assertThat(ofy().load().key(domain.getAutorenewBillingEvent()).now().getEventTime())
@ -197,11 +200,12 @@ public class DomainTransferApproveFlowTest
PollMessage gainingTransferPollMessage = PollMessage gainingTransferPollMessage =
getOnlyPollMessage(domain, "NewRegistrar", clock.nowUtc(), PollMessage.OneTime.class); getOnlyPollMessage(domain, "NewRegistrar", clock.nowUtc(), PollMessage.OneTime.class);
PollMessage gainingAutorenewPollMessage = getOnlyPollMessage( PollMessage gainingAutorenewPollMessage =
domain, getOnlyPollMessage(
"NewRegistrar", domain,
domain.getRegistrationExpirationTime(), "NewRegistrar",
PollMessage.Autorenew.class); domain.getRegistrationExpirationTime(),
PollMessage.Autorenew.class);
assertThat(gainingTransferPollMessage.getEventTime()).isEqualTo(clock.nowUtc()); assertThat(gainingTransferPollMessage.getEventTime()).isEqualTo(clock.nowUtc());
assertThat(gainingAutorenewPollMessage.getEventTime()) assertThat(gainingAutorenewPollMessage.getEventTime())
.isEqualTo(domain.getRegistrationExpirationTime()); .isEqualTo(domain.getRegistrationExpirationTime());
@ -228,8 +232,10 @@ public class DomainTransferApproveFlowTest
// After the expected grace time, the grace period should be gone. // After the expected grace time, the grace period should be gone.
assertThat( assertThat(
domain.cloneProjectedAtTime(clock.nowUtc().plus(registry.getTransferGracePeriodLength())) domain
.getGracePeriods()).isEmpty(); .cloneProjectedAtTime(clock.nowUtc().plus(registry.getTransferGracePeriodLength()))
.getGracePeriods())
.isEmpty();
} }
private void assertHistoryEntriesContainBillingEventsAndGracePeriods( private void assertHistoryEntriesContainBillingEventsAndGracePeriods(
@ -285,8 +291,7 @@ public class DomainTransferApproveFlowTest
} }
private void assertHistoryEntriesDoNotContainTransferBillingEventsOrGracePeriods( private void assertHistoryEntriesDoNotContainTransferBillingEventsOrGracePeriods(
BillingEvent.Cancellation.Builder... expectedCancellationBillingEvents) BillingEvent.Cancellation.Builder... expectedCancellationBillingEvents) throws Exception {
throws Exception {
domain = reloadResourceByForeignKey(); domain = reloadResourceByForeignKey();
final HistoryEntry historyEntryTransferApproved = final HistoryEntry historyEntryTransferApproved =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_APPROVE); getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_APPROVE);
@ -354,9 +359,7 @@ public class DomainTransferApproveFlowTest
.build()); .build());
setupDomainWithPendingTransfer("example", "net"); setupDomainWithPendingTransfer("example", "net");
doSuccessfulTest( doSuccessfulTest(
"net", "net", "domain_transfer_approve_net.xml", "domain_transfer_approve_response_net.xml");
"domain_transfer_approve_net.xml",
"domain_transfer_approve_response_net.xml");
} }
@Test @Test
@ -379,9 +382,7 @@ public class DomainTransferApproveFlowTest
public void testSuccess_autorenewBeforeTransfer() throws Exception { public void testSuccess_autorenewBeforeTransfer() throws Exception {
domain = reloadResourceByForeignKey(); domain = reloadResourceByForeignKey();
DateTime oldExpirationTime = clock.nowUtc().minusDays(1); DateTime oldExpirationTime = clock.nowUtc().minusDays(1);
persistResource(domain.asBuilder() persistResource(domain.asBuilder().setRegistrationExpirationTime(oldExpirationTime).build());
.setRegistrationExpirationTime(oldExpirationTime)
.build());
// The autorenew should be subsumed into the transfer resulting in 1 year of renewal in total. // The autorenew should be subsumed into the transfer resulting in 1 year of renewal in total.
clock.advanceOneMilli(); clock.advanceOneMilli();
doSuccessfulTest( doSuccessfulTest(
@ -395,7 +396,7 @@ public class DomainTransferApproveFlowTest
.setReason(Reason.RENEW) .setReason(Reason.RENEW)
.setTargetId("example.tld") .setTargetId("example.tld")
.setClientId("TheRegistrar") .setClientId("TheRegistrar")
.setEventTime(clock.nowUtc()) // The cancellation happens at the moment of transfer. .setEventTime(clock.nowUtc()) // The cancellation happens at the moment of transfer.
.setBillingTime( .setBillingTime(
oldExpirationTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength())) oldExpirationTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength()))
.setRecurringEventKey(domain.getAutorenewBillingEvent())); .setRecurringEventKey(domain.getAutorenewBillingEvent()));
@ -404,86 +405,109 @@ public class DomainTransferApproveFlowTest
@Test @Test
public void testFailure_badContactPassword() throws Exception { public void testFailure_badContactPassword() throws Exception {
// Change the contact's password so it does not match the password in the file. // Change the contact's password so it does not match the password in the file.
contact = persistResource( contact =
contact.asBuilder() persistResource(
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) contact
.build()); .asBuilder()
assertThrows( .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
BadAuthInfoForResourceException.class, .build());
() -> doFailingTest("domain_transfer_approve_contact_authinfo.xml")); EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_approve_contact_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_badDomainPassword() throws Exception { public void testFailure_badDomainPassword() throws Exception {
// Change the domain's password so it does not match the password in the file. // Change the domain's password so it does not match the password in the file.
persistResource(domain.asBuilder() persistResource(
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) domain
.build()); .asBuilder()
assertThrows( .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
BadAuthInfoForResourceException.class, .build());
() -> doFailingTest("domain_transfer_approve_domain_authinfo.xml")); EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_approve_domain_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_clientApproved() throws Exception { public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED); changeTransferStatus(TransferStatus.CLIENT_APPROVED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_clientRejected() throws Exception { public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED); changeTransferStatus(TransferStatus.CLIENT_REJECTED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_clientCancelled() throws Exception { public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED); changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_serverApproved() throws Exception { public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED); changeTransferStatus(TransferStatus.SERVER_APPROVED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_serverCancelled() throws Exception { public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_gainingClient() throws Exception { public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar"); setClientIdForFlow("NewRegistrar");
assertThrows( EppException thrown =
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_approve.xml")); expectThrows(
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
assertThrows( EppException thrown =
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_approve.xml")); expectThrows(
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_approve.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_deletedDomain() throws Exception { public void testFailure_deletedDomain() throws Exception {
persistResource( persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
ResourceDoesNotExistException thrown = ResourceDoesNotExistException thrown =
expectThrows( expectThrows(
ResourceDoesNotExistException.class, ResourceDoesNotExistException.class,
@ -505,11 +529,13 @@ public class DomainTransferApproveFlowTest
public void testFailure_notAuthorizedForTld() throws Exception { public void testFailure_notAuthorizedForTld() throws Exception {
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
assertThrows( EppException thrown =
NotAuthorizedForTldException.class, expectThrows(
() -> NotAuthorizedForTldException.class,
doSuccessfulTest( () ->
"tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml")); doSuccessfulTest(
"tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -559,8 +585,7 @@ public class DomainTransferApproveFlowTest
clock.advanceOneMilli(); clock.advanceOneMilli();
setUpGracePeriodDurations(); setUpGracePeriodDurations();
DomainTransactionRecord previousSuccessRecord = DomainTransactionRecord previousSuccessRecord =
DomainTransactionRecord.create( DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), TRANSFER_SUCCESSFUL, 1);
"tld", clock.nowUtc().plusDays(1), TRANSFER_SUCCESSFUL, 1);
// We only want to cancel TRANSFER_SUCCESSFUL records // We only want to cancel TRANSFER_SUCCESSFUL records
DomainTransactionRecord notCancellableRecord = DomainTransactionRecord notCancellableRecord =
DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), NET_ADDS_4_YR, 5); DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), NET_ADDS_4_YR, 5);

View file

@ -28,13 +28,14 @@ import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException; import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException;
@ -124,8 +125,10 @@ public class DomainTransferCancelFlowTest
// Transfer should have been cancelled. Verify correct fields were set. // Transfer should have been cancelled. Verify correct fields were set.
domain = reloadResourceByForeignKey(); domain = reloadResourceByForeignKey();
assertTransferFailed(domain, TransferStatus.CLIENT_CANCELLED, originalTransferData); assertTransferFailed(domain, TransferStatus.CLIENT_CANCELLED, originalTransferData);
assertAboutDomains().that(domain) assertAboutDomains()
.hasRegistrationExpirationTime(originalExpirationTime).and() .that(domain)
.hasRegistrationExpirationTime(originalExpirationTime)
.and()
.hasLastTransferTimeNotEqualTo(clock.nowUtc()); .hasLastTransferTimeNotEqualTo(clock.nowUtc());
assertAboutDomains() assertAboutDomains()
.that(domain) .that(domain)
@ -133,14 +136,16 @@ public class DomainTransferCancelFlowTest
DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST, DOMAIN_TRANSFER_CANCEL); DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST, DOMAIN_TRANSFER_CANCEL);
final HistoryEntry historyEntryTransferCancel = final HistoryEntry historyEntryTransferCancel =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_CANCEL); getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_CANCEL);
assertAboutHistoryEntries().that(historyEntryTransferCancel).hasClientId("NewRegistrar") assertAboutHistoryEntries()
.and().hasOtherClientId("TheRegistrar"); .that(historyEntryTransferCancel)
.hasClientId("NewRegistrar")
.and()
.hasOtherClientId("TheRegistrar");
// The only billing event left should be the original autorenew event, now reopened. // The only billing event left should be the original autorenew event, now reopened.
assertBillingEvents( assertBillingEvents(
getLosingClientAutorenewEvent().asBuilder().setRecurrenceEndTime(END_OF_TIME).build()); getLosingClientAutorenewEvent().asBuilder().setRecurrenceEndTime(END_OF_TIME).build());
// The poll message (in the future) to the gaining registrar for implicit ack should be gone. // The poll message (in the future) to the gaining registrar for implicit ack should be gone.
assertThat(getPollMessages("NewRegistrar", clock.nowUtc().plusMonths(1))) assertThat(getPollMessages("NewRegistrar", clock.nowUtc().plusMonths(1))).isEmpty();
.isEmpty();
// The poll message in the future to the losing registrar should be gone too, but there should // The poll message in the future to the losing registrar should be gone too, but there should
// be two at the current time to the losing registrar - one for the original autorenew event, // be two at the current time to the losing registrar - one for the original autorenew event,
// and another for the transfer being cancelled. // and another for the transfer being cancelled.
@ -157,14 +162,16 @@ public class DomainTransferCancelFlowTest
new PollMessage.OneTime.Builder() new PollMessage.OneTime.Builder()
.setClientId("TheRegistrar") .setClientId("TheRegistrar")
.setEventTime(clock.nowUtc()) .setEventTime(clock.nowUtc())
.setResponseData(ImmutableList.of(new DomainTransferResponse.Builder() .setResponseData(
.setFullyQualifiedDomainName(getUniqueIdFromCommand()) ImmutableList.of(
.setTransferStatus(TransferStatus.CLIENT_CANCELLED) new DomainTransferResponse.Builder()
.setTransferRequestTime(TRANSFER_REQUEST_TIME) .setFullyQualifiedDomainName(getUniqueIdFromCommand())
.setGainingClientId("NewRegistrar") .setTransferStatus(TransferStatus.CLIENT_CANCELLED)
.setLosingClientId("TheRegistrar") .setTransferRequestTime(TRANSFER_REQUEST_TIME)
.setPendingTransferExpirationTime(clock.nowUtc()) .setGainingClientId("NewRegistrar")
.build())) .setLosingClientId("TheRegistrar")
.setPendingTransferExpirationTime(clock.nowUtc())
.build()))
.setMsg("Transfer cancelled.") .setMsg("Transfer cancelled.")
.setParent(getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_CANCEL)) .setParent(getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_CANCEL))
.build()); .build());
@ -196,99 +203,124 @@ public class DomainTransferCancelFlowTest
@Test @Test
public void testSuccess_domainAuthInfo() throws Exception { public void testSuccess_domainAuthInfo() throws Exception {
doSuccessfulTest("domain_transfer_cancel_domain_authinfo.xml", doSuccessfulTest(
"domain_transfer_cancel_response.xml"); "domain_transfer_cancel_domain_authinfo.xml", "domain_transfer_cancel_response.xml");
} }
@Test @Test
public void testSuccess_contactAuthInfo() throws Exception { public void testSuccess_contactAuthInfo() throws Exception {
doSuccessfulTest("domain_transfer_cancel_contact_authinfo.xml", doSuccessfulTest(
"domain_transfer_cancel_response.xml"); "domain_transfer_cancel_contact_authinfo.xml", "domain_transfer_cancel_response.xml");
} }
@Test @Test
public void testFailure_badContactPassword() throws Exception { public void testFailure_badContactPassword() throws Exception {
// Change the contact's password so it does not match the password in the file. // Change the contact's password so it does not match the password in the file.
contact = persistResource( contact =
contact.asBuilder() persistResource(
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) contact
.build()); .asBuilder()
assertThrows( .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
BadAuthInfoForResourceException.class, .build());
() -> doFailingTest("domain_transfer_cancel_contact_authinfo.xml")); EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_cancel_contact_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_badDomainPassword() throws Exception { public void testFailure_badDomainPassword() throws Exception {
// Change the domain's password so it does not match the password in the file. // Change the domain's password so it does not match the password in the file.
domain = persistResource(domain.asBuilder() domain =
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) persistResource(
.build()); domain
assertThrows( .asBuilder()
BadAuthInfoForResourceException.class, .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
() -> doFailingTest("domain_transfer_cancel_domain_authinfo.xml")); .build());
EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_cancel_domain_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_clientApproved() throws Exception { public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED); changeTransferStatus(TransferStatus.CLIENT_APPROVED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_clientRejected() throws Exception { public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED); changeTransferStatus(TransferStatus.CLIENT_REJECTED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_clientCancelled() throws Exception { public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED); changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_serverApproved() throws Exception { public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED); changeTransferStatus(TransferStatus.SERVER_APPROVED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_serverCancelled() throws Exception { public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_sponsoringClient() throws Exception { public void testFailure_sponsoringClient() throws Exception {
setClientIdForFlow("TheRegistrar"); setClientIdForFlow("TheRegistrar");
assertThrows( EppException thrown =
NotTransferInitiatorException.class, () -> doFailingTest("domain_transfer_cancel.xml")); expectThrows(
NotTransferInitiatorException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
assertThrows( EppException thrown =
NotTransferInitiatorException.class, () -> doFailingTest("domain_transfer_cancel.xml")); expectThrows(
NotTransferInitiatorException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_deletedDomain() throws Exception { public void testFailure_deletedDomain() throws Exception {
domain = persistResource( domain =
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
ResourceDoesNotExistException thrown = ResourceDoesNotExistException thrown =
expectThrows( expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_cancel.xml")); ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
@ -308,10 +340,13 @@ public class DomainTransferCancelFlowTest
public void testFailure_notAuthorizedForTld() throws Exception { public void testFailure_notAuthorizedForTld() throws Exception {
persistResource( persistResource(
loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
assertThrows( EppException thrown =
NotAuthorizedForTldException.class, expectThrows(
() -> NotAuthorizedForTldException.class,
doSuccessfulTest("domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml")); () ->
doSuccessfulTest(
"domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test

View file

@ -20,9 +20,10 @@ import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.exceptions.NoTransferHistoryToQueryException; import google.registry.flows.exceptions.NoTransferHistoryToQueryException;
@ -47,18 +48,18 @@ public class DomainTransferQueryFlowTest
setupDomainWithPendingTransfer("example", "tld"); setupDomainWithPendingTransfer("example", "tld");
} }
private void doSuccessfulTest( private void doSuccessfulTest(String commandFilename, String expectedXmlFilename)
String commandFilename, throws Exception {
String expectedXmlFilename) throws Exception {
setEppInput(commandFilename); setEppInput(commandFilename);
// Replace the ROID in the xml file with the one generated in our test. // Replace the ROID in the xml file with the one generated in our test.
eppLoader.replaceAll("JD1234-REP", contact.getRepoId()); eppLoader.replaceAll("JD1234-REP", contact.getRepoId());
// Setup done; run the test. // Setup done; run the test.
assertTransactionalFlow(false); assertTransactionalFlow(false);
runFlowAssertResponse(loadFile(expectedXmlFilename)); runFlowAssertResponse(loadFile(expectedXmlFilename));
assertAboutDomains().that(domain).hasOneHistoryEntryEachOfTypes( assertAboutDomains()
HistoryEntry.Type.DOMAIN_CREATE, .that(domain)
HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST); .hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.DOMAIN_CREATE, HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST);
assertBillingEvents( assertBillingEvents(
getBillingEventForImplicitTransfer(), getBillingEventForImplicitTransfer(),
getGainingClientAutorenewEvent(), getGainingClientAutorenewEvent(),
@ -79,139 +80,142 @@ public class DomainTransferQueryFlowTest
@Test @Test
public void testSuccess() throws Exception { public void testSuccess() throws Exception {
doSuccessfulTest( doSuccessfulTest("domain_transfer_query.xml", "domain_transfer_query_response.xml");
"domain_transfer_query.xml",
"domain_transfer_query_response.xml");
} }
@Test @Test
public void testSuccess_sponsoringClient() throws Exception { public void testSuccess_sponsoringClient() throws Exception {
setClientIdForFlow("TheRegistrar"); setClientIdForFlow("TheRegistrar");
doSuccessfulTest( doSuccessfulTest("domain_transfer_query.xml", "domain_transfer_query_response.xml");
"domain_transfer_query.xml",
"domain_transfer_query_response.xml");
} }
@Test @Test
public void testSuccess_domainAuthInfo() throws Exception { public void testSuccess_domainAuthInfo() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
doSuccessfulTest( doSuccessfulTest(
"domain_transfer_query_domain_authinfo.xml", "domain_transfer_query_domain_authinfo.xml", "domain_transfer_query_response.xml");
"domain_transfer_query_response.xml");
} }
@Test @Test
public void testSuccess_contactAuthInfo() throws Exception { public void testSuccess_contactAuthInfo() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
doSuccessfulTest( doSuccessfulTest(
"domain_transfer_query_contact_authinfo.xml", "domain_transfer_query_contact_authinfo.xml", "domain_transfer_query_response.xml");
"domain_transfer_query_response.xml");
} }
@Test @Test
public void testSuccess_clientApproved() throws Exception { public void testSuccess_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED); changeTransferStatus(TransferStatus.CLIENT_APPROVED);
doSuccessfulTest( doSuccessfulTest(
"domain_transfer_query.xml", "domain_transfer_query.xml", "domain_transfer_query_response_client_approved.xml");
"domain_transfer_query_response_client_approved.xml");
} }
@Test @Test
public void testSuccess_clientRejected() throws Exception { public void testSuccess_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED); changeTransferStatus(TransferStatus.CLIENT_REJECTED);
doSuccessfulTest( doSuccessfulTest(
"domain_transfer_query.xml", "domain_transfer_query.xml", "domain_transfer_query_response_client_rejected.xml");
"domain_transfer_query_response_client_rejected.xml");
} }
@Test @Test
public void testSuccess_clientCancelled() throws Exception { public void testSuccess_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED); changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
doSuccessfulTest( doSuccessfulTest(
"domain_transfer_query.xml", "domain_transfer_query.xml", "domain_transfer_query_response_client_cancelled.xml");
"domain_transfer_query_response_client_cancelled.xml");
} }
@Test @Test
public void testSuccess_serverApproved() throws Exception { public void testSuccess_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED); changeTransferStatus(TransferStatus.SERVER_APPROVED);
doSuccessfulTest( doSuccessfulTest(
"domain_transfer_query.xml", "domain_transfer_query.xml", "domain_transfer_query_response_server_approved.xml");
"domain_transfer_query_response_server_approved.xml");
} }
@Test @Test
public void testSuccess_serverCancelled() throws Exception { public void testSuccess_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
doSuccessfulTest( doSuccessfulTest(
"domain_transfer_query.xml", "domain_transfer_query.xml", "domain_transfer_query_response_server_cancelled.xml");
"domain_transfer_query_response_server_cancelled.xml");
} }
@Test @Test
public void testSuccess_tenYears() throws Exception { public void testSuccess_tenYears() throws Exception {
// Extend registration by 9 years here; with the extra 1 year from the transfer, we should // Extend registration by 9 years here; with the extra 1 year from the transfer, we should
// hit the 10-year capping. // hit the 10-year capping.
domain = persistResource(domain.asBuilder() domain =
.setRegistrationExpirationTime(domain.getRegistrationExpirationTime().plusYears(9)) persistResource(
.build()); domain
doSuccessfulTest( .asBuilder()
"domain_transfer_query.xml", .setRegistrationExpirationTime(domain.getRegistrationExpirationTime().plusYears(9))
"domain_transfer_query_response_10_years.xml"); .build());
doSuccessfulTest("domain_transfer_query.xml", "domain_transfer_query_response_10_years.xml");
} }
@Test @Test
public void testFailure_pendingDeleteDomain() throws Exception { public void testFailure_pendingDeleteDomain() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
domain = persistResource( domain =
domain.asBuilder().setDeletionTime(clock.nowUtc().plusDays(1)).build()); persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().plusDays(1)).build());
doSuccessfulTest( doSuccessfulTest(
"domain_transfer_query.xml", "domain_transfer_query.xml", "domain_transfer_query_response_server_cancelled.xml");
"domain_transfer_query_response_server_cancelled.xml");
} }
@Test @Test
public void testFailure_badContactPassword() throws Exception { public void testFailure_badContactPassword() throws Exception {
// Change the contact's password so it does not match the password in the file. // Change the contact's password so it does not match the password in the file.
contact = persistResource( contact =
contact.asBuilder() persistResource(
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) contact
.build()); .asBuilder()
assertThrows( .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
BadAuthInfoForResourceException.class, .build());
() -> doFailingTest("domain_transfer_query_contact_authinfo.xml")); EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_query_contact_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_badDomainPassword() throws Exception { public void testFailure_badDomainPassword() throws Exception {
// Change the domain's password so it does not match the password in the file. // Change the domain's password so it does not match the password in the file.
domain = persistResource(domain.asBuilder() domain =
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) persistResource(
.build()); domain
assertThrows( .asBuilder()
BadAuthInfoForResourceException.class, .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
() -> doFailingTest("domain_transfer_query_domain_authinfo.xml")); .build());
EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_query_domain_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
assertThrows( EppException thrown =
NoTransferHistoryToQueryException.class, () -> doFailingTest("domain_transfer_query.xml")); expectThrows(
NoTransferHistoryToQueryException.class,
() -> doFailingTest("domain_transfer_query.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
assertThrows( EppException thrown =
NotAuthorizedToViewTransferException.class, expectThrows(
() -> doFailingTest("domain_transfer_query.xml")); NotAuthorizedToViewTransferException.class,
() -> doFailingTest("domain_transfer_query.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_deletedDomain() throws Exception { public void testFailure_deletedDomain() throws Exception {
domain = persistResource( domain =
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
ResourceDoesNotExistException thrown = ResourceDoesNotExistException thrown =
expectThrows( expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_query.xml")); ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_query.xml"));

View file

@ -30,12 +30,13 @@ import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException; import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
@ -83,10 +84,8 @@ public class DomainTransferRejectFlowTest
getGainingClientAutorenewEvent(), getGainingClientAutorenewEvent(),
getLosingClientAutorenewEvent()); getLosingClientAutorenewEvent());
// Look in the future and make sure the poll messages for implicit ack are there. // Look in the future and make sure the poll messages for implicit ack are there.
assertThat(getPollMessages("NewRegistrar", clock.nowUtc().plusMonths(1))) assertThat(getPollMessages("NewRegistrar", clock.nowUtc().plusMonths(1))).hasSize(1);
.hasSize(1); assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))).hasSize(1);
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1)))
.hasSize(1);
// Setup done; run the test. // Setup done; run the test.
assertTransactionalFlow(true); assertTransactionalFlow(true);
DateTime originalExpirationTime = domain.getRegistrationExpirationTime(); DateTime originalExpirationTime = domain.getRegistrationExpirationTime();
@ -96,22 +95,22 @@ public class DomainTransferRejectFlowTest
// Transfer should have been rejected. Verify correct fields were set. // Transfer should have been rejected. Verify correct fields were set.
domain = reloadResourceByForeignKey(); domain = reloadResourceByForeignKey();
assertTransferFailed(domain, TransferStatus.CLIENT_REJECTED, originalTransferData); assertTransferFailed(domain, TransferStatus.CLIENT_REJECTED, originalTransferData);
assertAboutDomains().that(domain) assertAboutDomains()
.hasRegistrationExpirationTime(originalExpirationTime).and() .that(domain)
.hasLastTransferTimeNotEqualTo(clock.nowUtc()).and() .hasRegistrationExpirationTime(originalExpirationTime)
.and()
.hasLastTransferTimeNotEqualTo(clock.nowUtc())
.and()
.hasOneHistoryEntryEachOfTypes( .hasOneHistoryEntryEachOfTypes(
DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST, DOMAIN_TRANSFER_REJECT); DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST, DOMAIN_TRANSFER_REJECT);
final HistoryEntry historyEntryTransferRejected = final HistoryEntry historyEntryTransferRejected =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REJECT); getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REJECT);
assertAboutHistoryEntries() assertAboutHistoryEntries().that(historyEntryTransferRejected).hasOtherClientId("NewRegistrar");
.that(historyEntryTransferRejected)
.hasOtherClientId("NewRegistrar");
// The only billing event left should be the original autorenew event, now reopened. // The only billing event left should be the original autorenew event, now reopened.
assertBillingEvents( assertBillingEvents(
getLosingClientAutorenewEvent().asBuilder().setRecurrenceEndTime(END_OF_TIME).build()); getLosingClientAutorenewEvent().asBuilder().setRecurrenceEndTime(END_OF_TIME).build());
// The poll message (in the future) to the losing registrar for implicit ack should be gone. // The poll message (in the future) to the losing registrar for implicit ack should be gone.
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))) assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))).isEmpty();
.isEmpty();
// The poll message in the future to the gaining registrar should be gone too, but there // The poll message in the future to the gaining registrar should be gone too, but there
// should be one at the current time to the gaining registrar. // should be one at the current time to the gaining registrar.
PollMessage gainingPollMessage = getOnlyPollMessage("NewRegistrar"); PollMessage gainingPollMessage = getOnlyPollMessage("NewRegistrar");
@ -162,24 +161,27 @@ public class DomainTransferRejectFlowTest
@Test @Test
public void testSuccess_domainAuthInfo() throws Exception { public void testSuccess_domainAuthInfo() throws Exception {
doSuccessfulTest("domain_transfer_reject_domain_authinfo.xml", doSuccessfulTest(
"domain_transfer_reject_response.xml"); "domain_transfer_reject_domain_authinfo.xml", "domain_transfer_reject_response.xml");
} }
@Test @Test
public void testSuccess_contactAuthInfo() throws Exception { public void testSuccess_contactAuthInfo() throws Exception {
doSuccessfulTest("domain_transfer_reject_contact_authinfo.xml", doSuccessfulTest(
"domain_transfer_reject_response.xml"); "domain_transfer_reject_contact_authinfo.xml", "domain_transfer_reject_response.xml");
} }
@Test @Test
public void testFailure_notAuthorizedForTld() throws Exception { public void testFailure_notAuthorizedForTld() throws Exception {
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
assertThrows( EppException thrown =
NotAuthorizedForTldException.class, expectThrows(
() -> NotAuthorizedForTldException.class,
doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml")); () ->
doSuccessfulTest(
"domain_transfer_reject.xml", "domain_transfer_reject_response.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -193,87 +195,111 @@ public class DomainTransferRejectFlowTest
@Test @Test
public void testFailure_badContactPassword() throws Exception { public void testFailure_badContactPassword() throws Exception {
// Change the contact's password so it does not match the password in the file. // Change the contact's password so it does not match the password in the file.
contact = persistResource( contact =
contact.asBuilder() persistResource(
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) contact
.build()); .asBuilder()
assertThrows( .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
BadAuthInfoForResourceException.class, .build());
() -> doFailingTest("domain_transfer_reject_contact_authinfo.xml")); EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_reject_contact_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_badDomainPassword() throws Exception { public void testFailure_badDomainPassword() throws Exception {
// Change the domain's password so it does not match the password in the file. // Change the domain's password so it does not match the password in the file.
domain = persistResource( domain =
domain.asBuilder() persistResource(
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) domain
.build()); .asBuilder()
assertThrows( .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
BadAuthInfoForResourceException.class, .build());
() -> doFailingTest("domain_transfer_reject_domain_authinfo.xml")); EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_reject_domain_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_clientApproved() throws Exception { public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED); changeTransferStatus(TransferStatus.CLIENT_APPROVED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_clientRejected() throws Exception { public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED); changeTransferStatus(TransferStatus.CLIENT_REJECTED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_clientCancelled() throws Exception { public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED); changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_serverApproved() throws Exception { public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED); changeTransferStatus(TransferStatus.SERVER_APPROVED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_serverCancelled() throws Exception { public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
assertThrows( EppException thrown =
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml")); expectThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_gainingClient() throws Exception { public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar"); setClientIdForFlow("NewRegistrar");
assertThrows( EppException thrown =
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml")); expectThrows(
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
assertThrows( EppException thrown =
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml")); expectThrows(
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_deletedDomain() throws Exception { public void testFailure_deletedDomain() throws Exception {
domain = persistResource( domain =
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
ResourceDoesNotExistException thrown = ResourceDoesNotExistException thrown =
expectThrows( expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_reject.xml")); ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_reject.xml"));
@ -322,8 +348,7 @@ public class DomainTransferRejectFlowTest
public void testIcannTransactionRecord_cancelsPreviousRecords() throws Exception { public void testIcannTransactionRecord_cancelsPreviousRecords() throws Exception {
setUpGracePeriodDurations(); setUpGracePeriodDurations();
DomainTransactionRecord previousSuccessRecord = DomainTransactionRecord previousSuccessRecord =
DomainTransactionRecord.create( DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), TRANSFER_SUCCESSFUL, 1);
"tld", clock.nowUtc().plusDays(1), TRANSFER_SUCCESSFUL, 1);
// We only want to cancel TRANSFER_SUCCESSFUL records // We only want to cancel TRANSFER_SUCCESSFUL records
DomainTransactionRecord notCancellableRecord = DomainTransactionRecord notCancellableRecord =
DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), NET_RENEWS_3_YR, 5); DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), NET_RENEWS_3_YR, 5);

View file

@ -31,6 +31,7 @@ import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.JUnitBackports.assertThrows;
@ -49,6 +50,7 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.EppRequestSource; import google.registry.flows.EppRequestSource;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@ -136,9 +138,12 @@ public class DomainTransferRequestFlowTest
DomainResource domain, DomainResource domain,
DateTime automaticTransferTime, DateTime automaticTransferTime,
Period expectedPeriod, Period expectedPeriod,
DateTime expectedExpirationTime) throws Exception { DateTime expectedExpirationTime)
assertAboutDomains().that(domain) throws Exception {
.hasCurrentSponsorClientId("TheRegistrar").and() assertAboutDomains()
.that(domain)
.hasCurrentSponsorClientId("TheRegistrar")
.and()
.hasStatusValue(StatusValue.PENDING_TRANSFER); .hasStatusValue(StatusValue.PENDING_TRANSFER);
Trid expectedTrid = Trid expectedTrid =
Trid.create( Trid.create(
@ -149,7 +154,9 @@ public class DomainTransferRequestFlowTest
// Compare against only the following fields by rebuilding the existing TransferData. // Compare against only the following fields by rebuilding the existing TransferData.
// Equivalent to assertThat(transferData.getGainingClientId()).isEqualTo("NewReg") // Equivalent to assertThat(transferData.getGainingClientId()).isEqualTo("NewReg")
// and similar individual assertions, but produces a nicer error message this way. // and similar individual assertions, but produces a nicer error message this way.
domain.getTransferData().asBuilder() domain
.getTransferData()
.asBuilder()
.setGainingClientId("NewRegistrar") .setGainingClientId("NewRegistrar")
.setLosingClientId("TheRegistrar") .setLosingClientId("TheRegistrar")
.setTransferRequestTrid(expectedTrid) .setTransferRequestTrid(expectedTrid)
@ -166,9 +173,12 @@ public class DomainTransferRequestFlowTest
private void assertTransferApproved( private void assertTransferApproved(
DomainResource domain, DateTime automaticTransferTime, Period expectedPeriod) DomainResource domain, DateTime automaticTransferTime, Period expectedPeriod)
throws Exception { throws Exception {
assertAboutDomains().that(domain) assertAboutDomains()
.hasCurrentSponsorClientId("NewRegistrar").and() .that(domain)
.hasLastTransferTime(automaticTransferTime).and() .hasCurrentSponsorClientId("NewRegistrar")
.and()
.hasLastTransferTime(automaticTransferTime)
.and()
.doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER); .doesNotHaveStatusValue(StatusValue.PENDING_TRANSFER);
Trid expectedTrid = Trid expectedTrid =
Trid.create( Trid.create(
@ -190,7 +200,7 @@ public class DomainTransferRequestFlowTest
} }
/** /**
* Runs a successful test. The extraExpectedBillingEvents parameter consists of cancellation * Runs a successful test. The extraExpectedBillingEvents parameter consists of cancellation
* billing event builders that have had all of their attributes set except for the parent history * billing event builders that have had all of their attributes set except for the parent history
* entry, which is filled in during the execution of this method. * entry, which is filled in during the execution of this method.
*/ */
@ -200,7 +210,8 @@ public class DomainTransferRequestFlowTest
DateTime expectedExpirationTime, DateTime expectedExpirationTime,
Map<String, String> substitutions, Map<String, String> substitutions,
Optional<Money> transferCost, Optional<Money> transferCost,
BillingEvent.Cancellation.Builder... extraExpectedBillingEvents) throws Exception { BillingEvent.Cancellation.Builder... extraExpectedBillingEvents)
throws Exception {
setEppInput(commandFilename, substitutions); setEppInput(commandFilename, substitutions);
ImmutableSet<GracePeriod> originalGracePeriods = domain.getGracePeriods(); ImmutableSet<GracePeriod> originalGracePeriods = domain.getGracePeriods();
// Replace the ROID in the xml file with the one generated in our test. // Replace the ROID in the xml file with the one generated in our test.
@ -216,7 +227,8 @@ public class DomainTransferRequestFlowTest
// Transfer should have been requested. // Transfer should have been requested.
domain = reloadResourceByForeignKey(); domain = reloadResourceByForeignKey();
// Verify that HistoryEntry was created. // Verify that HistoryEntry was created.
assertAboutDomains().that(domain) assertAboutDomains()
.that(domain)
.hasOneHistoryEntryEachOfTypes(DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST); .hasOneHistoryEntryEachOfTypes(DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST);
final HistoryEntry historyEntryTransferRequest = final HistoryEntry historyEntryTransferRequest =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST); getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST);
@ -285,13 +297,12 @@ public class DomainTransferRequestFlowTest
// request by definition takes place on day 1, so we need to edit the times in the // request by definition takes place on day 1, so we need to edit the times in the
// autorenew events from the base test case. // autorenew events from the base test case.
BillingEvent.Recurring losingClientAutorenew = BillingEvent.Recurring losingClientAutorenew =
getLosingClientAutorenewEvent().asBuilder() getLosingClientAutorenewEvent()
.asBuilder()
.setRecurrenceEndTime(implicitTransferTime) .setRecurrenceEndTime(implicitTransferTime)
.build(); .build();
BillingEvent.Recurring gainingClientAutorenew = BillingEvent.Recurring gainingClientAutorenew =
getGainingClientAutorenewEvent().asBuilder() getGainingClientAutorenewEvent().asBuilder().setEventTime(expectedExpirationTime).build();
.setEventTime(expectedExpirationTime)
.build();
// Construct extra billing events expected by the specific test. // Construct extra billing events expected by the specific test.
Set<BillingEvent> extraBillingEvents = Set<BillingEvent> extraBillingEvents =
Stream.of(extraExpectedBillingEvents) Stream.of(extraExpectedBillingEvents)
@ -364,10 +375,10 @@ public class DomainTransferRequestFlowTest
// Two poll messages on the gaining registrar's side at the expected expiration time: a // Two poll messages on the gaining registrar's side at the expected expiration time: a
// (OneTime) transfer approved message, and an Autorenew poll message. // (OneTime) transfer approved message, and an Autorenew poll message.
assertThat(getPollMessages("NewRegistrar", expectedExpirationTime)).hasSize(2); assertThat(getPollMessages("NewRegistrar", expectedExpirationTime)).hasSize(2);
PollMessage transferApprovedPollMessage = getOnlyPollMessage( PollMessage transferApprovedPollMessage =
"NewRegistrar", implicitTransferTime, PollMessage.OneTime.class); getOnlyPollMessage("NewRegistrar", implicitTransferTime, PollMessage.OneTime.class);
PollMessage autorenewPollMessage = getOnlyPollMessage( PollMessage autorenewPollMessage =
"NewRegistrar", expectedExpirationTime, PollMessage.Autorenew.class); getOnlyPollMessage("NewRegistrar", expectedExpirationTime, PollMessage.Autorenew.class);
assertThat(transferApprovedPollMessage.getEventTime()).isEqualTo(implicitTransferTime); assertThat(transferApprovedPollMessage.getEventTime()).isEqualTo(implicitTransferTime);
assertThat(autorenewPollMessage.getEventTime()).isEqualTo(expectedExpirationTime); assertThat(autorenewPollMessage.getEventTime()).isEqualTo(expectedExpirationTime);
assertThat( assertThat(
@ -431,15 +442,14 @@ public class DomainTransferRequestFlowTest
// OneTime messages to gaining and losing registrars plus the gaining client autorenew. // OneTime messages to gaining and losing registrars plus the gaining client autorenew.
assertPollMessagesEqual( assertPollMessagesEqual(
Iterables.filter( Iterables.filter(
ofy().load() ofy()
.load()
// Use toArray() to coerce the type to something keys() will accept. // Use toArray() to coerce the type to something keys() will accept.
.keys(domain.getTransferData().getServerApproveEntities().toArray(new Key<?>[]{})) .keys(domain.getTransferData().getServerApproveEntities().toArray(new Key<?>[] {}))
.values(), .values(),
PollMessage.class), PollMessage.class),
ImmutableList.of( ImmutableList.of(
transferApprovedPollMessage, transferApprovedPollMessage, losingTransferApprovedPollMessage, autorenewPollMessage));
losingTransferApprovedPollMessage,
autorenewPollMessage));
} }
private void assertAboutDomainAfterAutomaticTransfer( private void assertAboutDomainAfterAutomaticTransfer(
@ -448,15 +458,23 @@ public class DomainTransferRequestFlowTest
Registry registry = Registry.get(domain.getTld()); Registry registry = Registry.get(domain.getTld());
DomainResource domainAfterAutomaticTransfer = domain.cloneProjectedAtTime(implicitTransferTime); DomainResource domainAfterAutomaticTransfer = domain.cloneProjectedAtTime(implicitTransferTime);
assertTransferApproved(domainAfterAutomaticTransfer, implicitTransferTime, expectedPeriod); assertTransferApproved(domainAfterAutomaticTransfer, implicitTransferTime, expectedPeriod);
assertAboutDomains().that(domainAfterAutomaticTransfer) assertAboutDomains()
.that(domainAfterAutomaticTransfer)
.hasRegistrationExpirationTime(expectedExpirationTime); .hasRegistrationExpirationTime(expectedExpirationTime);
assertThat(ofy().load().key(domainAfterAutomaticTransfer.getAutorenewBillingEvent()).now() assertThat(
.getEventTime()) ofy()
.isEqualTo(expectedExpirationTime); .load()
.key(domainAfterAutomaticTransfer.getAutorenewBillingEvent())
.now()
.getEventTime())
.isEqualTo(expectedExpirationTime);
// And after the expected grace time, the grace period should be gone. // And after the expected grace time, the grace period should be gone.
DomainResource afterGracePeriod = domain.cloneProjectedAtTime( DomainResource afterGracePeriod =
clock.nowUtc().plus(registry.getAutomaticTransferLength()).plus( domain.cloneProjectedAtTime(
registry.getTransferGracePeriodLength())); clock
.nowUtc()
.plus(registry.getAutomaticTransferLength())
.plus(registry.getTransferGracePeriodLength()));
assertThat(afterGracePeriod.getGracePeriods()).isEmpty(); assertThat(afterGracePeriod.getGracePeriods()).isEmpty();
} }
@ -464,7 +482,8 @@ public class DomainTransferRequestFlowTest
String commandFilename, String commandFilename,
String expectedXmlFilename, String expectedXmlFilename,
DateTime expectedExpirationTime, DateTime expectedExpirationTime,
BillingEvent.Cancellation.Builder... extraExpectedBillingEvents) throws Exception { BillingEvent.Cancellation.Builder... extraExpectedBillingEvents)
throws Exception {
doSuccessfulTest( doSuccessfulTest(
commandFilename, commandFilename,
expectedXmlFilename, expectedXmlFilename,
@ -475,9 +494,8 @@ public class DomainTransferRequestFlowTest
} }
private void doSuccessfulTest( private void doSuccessfulTest(
String commandFilename, String commandFilename, String expectedXmlFilename, Map<String, String> substitutions)
String expectedXmlFilename, throws Exception {
Map<String, String> substitutions) throws Exception {
clock.advanceOneMilli(); clock.advanceOneMilli();
doSuccessfulTest( doSuccessfulTest(
commandFilename, commandFilename,
@ -502,7 +520,8 @@ public class DomainTransferRequestFlowTest
Optional<Money> transferCost, Optional<Money> transferCost,
Period expectedPeriod, Period expectedPeriod,
Duration expectedAutomaticTransferLength, Duration expectedAutomaticTransferLength,
BillingEvent.Cancellation.Builder... extraExpectedBillingEvents) throws Exception { BillingEvent.Cancellation.Builder... extraExpectedBillingEvents)
throws Exception {
setEppInput(commandFilename, substitutions); setEppInput(commandFilename, substitutions);
ImmutableSet<GracePeriod> originalGracePeriods = domain.getGracePeriods(); ImmutableSet<GracePeriod> originalGracePeriods = domain.getGracePeriods();
// Replace the ROID in the xml file with the one generated in our test. // Replace the ROID in the xml file with the one generated in our test.
@ -526,7 +545,8 @@ public class DomainTransferRequestFlowTest
domain = reloadResourceByForeignKey(); domain = reloadResourceByForeignKey();
} }
// Verify that HistoryEntry was created. // Verify that HistoryEntry was created.
assertAboutDomains().that(domain) assertAboutDomains()
.that(domain)
.hasOneHistoryEntryEachOfTypes(DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST); .hasOneHistoryEntryEachOfTypes(DOMAIN_CREATE, DOMAIN_TRANSFER_REQUEST);
final HistoryEntry historyEntryTransferRequest = final HistoryEntry historyEntryTransferRequest =
getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST); getOnlyHistoryEntryOfType(domain, DOMAIN_TRANSFER_REQUEST);
@ -556,9 +576,8 @@ public class DomainTransferRequestFlowTest
} }
private void runTest( private void runTest(
String commandFilename, String commandFilename, UserPrivileges userPrivileges, Map<String, String> substitutions)
UserPrivileges userPrivileges, throws Exception {
Map<String, String> substitutions) throws Exception {
setEppInput(commandFilename, substitutions); setEppInput(commandFilename, substitutions);
// Replace the ROID in the xml file with the one generated in our test. // Replace the ROID in the xml file with the one generated in our test.
eppLoader.replaceAll("JD1234-REP", contact.getRepoId()); eppLoader.replaceAll("JD1234-REP", contact.getRepoId());
@ -571,8 +590,8 @@ public class DomainTransferRequestFlowTest
runTest(commandFilename, userPrivileges, ImmutableMap.of()); runTest(commandFilename, userPrivileges, ImmutableMap.of());
} }
private void doFailingTest( private void doFailingTest(String commandFilename, Map<String, String> substitutions)
String commandFilename, Map<String, String> substitutions) throws Exception { throws Exception {
runTest(commandFilename, UserPrivileges.NORMAL, substitutions); runTest(commandFilename, UserPrivileges.NORMAL, substitutions);
} }
@ -645,73 +664,91 @@ public class DomainTransferRequestFlowTest
@Test @Test
public void testFailure_refundableFee_v06() throws Exception { public void testFailure_refundableFee_v06() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
UnsupportedFeeAttributeException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_06_MAP)); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_06_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_refundableFee_v11() throws Exception { public void testFailure_refundableFee_v11() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
UnsupportedFeeAttributeException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_11_MAP)); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_11_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_refundableFee_v12() throws Exception { public void testFailure_refundableFee_v12() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
UnsupportedFeeAttributeException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_12_MAP)); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_12_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_gracePeriodFee_v06() throws Exception { public void testFailure_gracePeriodFee_v06() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
UnsupportedFeeAttributeException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_06_MAP)); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_06_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_gracePeriodFee_v11() throws Exception { public void testFailure_gracePeriodFee_v11() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
UnsupportedFeeAttributeException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_11_MAP)); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_11_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_gracePeriodFee_v12() throws Exception { public void testFailure_gracePeriodFee_v12() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
UnsupportedFeeAttributeException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_12_MAP)); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_12_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_appliedFee_v06() throws Exception { public void testFailure_appliedFee_v06() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
UnsupportedFeeAttributeException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_06_MAP)); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_06_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_appliedFee_v11() throws Exception { public void testFailure_appliedFee_v11() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
UnsupportedFeeAttributeException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_11_MAP)); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_11_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_appliedFee_v12() throws Exception { public void testFailure_appliedFee_v12() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
UnsupportedFeeAttributeException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_12_MAP)); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_12_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -723,8 +760,7 @@ public class DomainTransferRequestFlowTest
.setAutomaticTransferLength(Duration.standardMinutes(15)) .setAutomaticTransferLength(Duration.standardMinutes(15))
.build()); .build());
doSuccessfulTest( doSuccessfulTest(
"domain_transfer_request.xml", "domain_transfer_request.xml", "domain_transfer_request_response_15_minutes.xml");
"domain_transfer_request_response_15_minutes.xml");
} }
@Test @Test
@ -742,17 +778,18 @@ public class DomainTransferRequestFlowTest
public void testSuccess_missingPeriod_defaultsToOneYear() throws Exception { public void testSuccess_missingPeriod_defaultsToOneYear() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
doSuccessfulTest( doSuccessfulTest(
"domain_transfer_request_missing_period.xml", "domain_transfer_request_missing_period.xml", "domain_transfer_request_response.xml");
"domain_transfer_request_response.xml");
} }
@Test @Test
public void testFailure_multiYearPeriod() throws Exception { public void testFailure_multiYearPeriod() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
clock.advanceOneMilli(); clock.advanceOneMilli();
assertThrows( EppException thrown =
TransferPeriodMustBeOneYearException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_2_years.xml")); TransferPeriodMustBeOneYearException.class,
() -> doFailingTest("domain_transfer_request_2_years.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -804,24 +841,26 @@ public class DomainTransferRequestFlowTest
} }
@Test @Test
public void testSuccess_superuserExtension_zeroPeriod_autorenewGraceActive() public void testSuccess_superuserExtension_zeroPeriod_autorenewGraceActive() throws Exception {
throws Exception {
eppRequestSource = EppRequestSource.TOOL; eppRequestSource = EppRequestSource.TOOL;
setupDomain("example", "tld"); setupDomain("example", "tld");
Key<BillingEvent.Recurring> existingAutorenewEvent = Key<BillingEvent.Recurring> existingAutorenewEvent = domain.getAutorenewBillingEvent();
domain.getAutorenewBillingEvent();
// Set domain to have auto-renewed just before the transfer request, so that it will have an // Set domain to have auto-renewed just before the transfer request, so that it will have an
// active autorenew grace period spanning the entire transfer window. // active autorenew grace period spanning the entire transfer window.
DateTime autorenewTime = clock.nowUtc().minusDays(1); DateTime autorenewTime = clock.nowUtc().minusDays(1);
DateTime expirationTime = autorenewTime.plusYears(1); DateTime expirationTime = autorenewTime.plusYears(1);
domain = persistResource(domain.asBuilder() domain =
.setRegistrationExpirationTime(expirationTime) persistResource(
.addGracePeriod(GracePeriod.createForRecurring( domain
GracePeriodStatus.AUTO_RENEW, .asBuilder()
autorenewTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength()), .setRegistrationExpirationTime(expirationTime)
"TheRegistrar", .addGracePeriod(
existingAutorenewEvent)) GracePeriod.createForRecurring(
.build()); GracePeriodStatus.AUTO_RENEW,
autorenewTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength()),
"TheRegistrar",
existingAutorenewEvent))
.build());
clock.advanceOneMilli(); clock.advanceOneMilli();
doSuccessfulSuperuserExtensionTest( doSuccessfulSuperuserExtensionTest(
"domain_transfer_request_superuser_extension.xml", "domain_transfer_request_superuser_extension.xml",
@ -865,9 +904,9 @@ public class DomainTransferRequestFlowTest
public void testSuccess_cappedExpiration() throws Exception { public void testSuccess_cappedExpiration() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
// Set the domain to expire 10 years from now (as if it were just created with a 10-year term). // Set the domain to expire 10 years from now (as if it were just created with a 10-year term).
domain = persistResource(domain.asBuilder() domain =
.setRegistrationExpirationTime(clock.nowUtc().plusYears(10)) persistResource(
.build()); domain.asBuilder().setRegistrationExpirationTime(clock.nowUtc().plusYears(10)).build());
// New expiration time should be capped at exactly 10 years from the transfer server-approve // New expiration time should be capped at exactly 10 years from the transfer server-approve
// time, so the domain only ends up gaining the 5-day transfer window's worth of extra // time, so the domain only ends up gaining the 5-day transfer window's worth of extra
// registration time. // registration time.
@ -882,8 +921,7 @@ public class DomainTransferRequestFlowTest
public void testSuccess_domainAuthInfo() throws Exception { public void testSuccess_domainAuthInfo() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
doSuccessfulTest( doSuccessfulTest(
"domain_transfer_request_domain_authinfo.xml", "domain_transfer_request_domain_authinfo.xml", "domain_transfer_request_response.xml");
"domain_transfer_request_response.xml");
} }
@Test @Test
@ -910,11 +948,13 @@ public class DomainTransferRequestFlowTest
setupDomain("example", "tld"); setupDomain("example", "tld");
persistResource( persistResource(
loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
assertThrows( EppException thrown =
NotAuthorizedForTldException.class, expectThrows(
() -> NotAuthorizedForTldException.class,
doSuccessfulTest( () ->
"domain_transfer_request.xml", "domain_transfer_request_response.xml")); doSuccessfulTest(
"domain_transfer_request.xml", "domain_transfer_request_response.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -935,14 +975,18 @@ public class DomainTransferRequestFlowTest
DateTime autorenewTime = DateTime autorenewTime =
clock.nowUtc().minus(Registry.get("tld").getAutoRenewGracePeriodLength()).plusDays(1); clock.nowUtc().minus(Registry.get("tld").getAutoRenewGracePeriodLength()).plusDays(1);
DateTime expirationTime = autorenewTime.plusYears(1); DateTime expirationTime = autorenewTime.plusYears(1);
domain = persistResource(domain.asBuilder() domain =
.setRegistrationExpirationTime(expirationTime) persistResource(
.addGracePeriod(GracePeriod.createForRecurring( domain
GracePeriodStatus.AUTO_RENEW, .asBuilder()
autorenewTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength()), .setRegistrationExpirationTime(expirationTime)
"TheRegistrar", .addGracePeriod(
domain.getAutorenewBillingEvent())) GracePeriod.createForRecurring(
.build()); GracePeriodStatus.AUTO_RENEW,
autorenewTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength()),
"TheRegistrar",
domain.getAutorenewBillingEvent()))
.build());
clock.advanceOneMilli(); clock.advanceOneMilli();
// Since the autorenew grace period will have ended by the automatic transfer time, subsuming // Since the autorenew grace period will have ended by the automatic transfer time, subsuming
// will not occur in the server-approve case, so the transfer will add 1 year to the current // will not occur in the server-approve case, so the transfer will add 1 year to the current
@ -958,20 +1002,23 @@ public class DomainTransferRequestFlowTest
@Test @Test
public void testSuccess_autorenewGraceActive_throughoutTransferWindow() throws Exception { public void testSuccess_autorenewGraceActive_throughoutTransferWindow() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
Key<BillingEvent.Recurring> existingAutorenewEvent = Key<BillingEvent.Recurring> existingAutorenewEvent = domain.getAutorenewBillingEvent();
domain.getAutorenewBillingEvent();
// Set domain to have auto-renewed just before the transfer request, so that it will have an // Set domain to have auto-renewed just before the transfer request, so that it will have an
// active autorenew grace period spanning the entire transfer window. // active autorenew grace period spanning the entire transfer window.
DateTime autorenewTime = clock.nowUtc().minusDays(1); DateTime autorenewTime = clock.nowUtc().minusDays(1);
DateTime expirationTime = autorenewTime.plusYears(1); DateTime expirationTime = autorenewTime.plusYears(1);
domain = persistResource(domain.asBuilder() domain =
.setRegistrationExpirationTime(expirationTime) persistResource(
.addGracePeriod(GracePeriod.createForRecurring( domain
GracePeriodStatus.AUTO_RENEW, .asBuilder()
autorenewTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength()), .setRegistrationExpirationTime(expirationTime)
"TheRegistrar", .addGracePeriod(
existingAutorenewEvent)) GracePeriod.createForRecurring(
.build()); GracePeriodStatus.AUTO_RENEW,
autorenewTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength()),
"TheRegistrar",
existingAutorenewEvent))
.build());
clock.advanceOneMilli(); clock.advanceOneMilli();
// The transfer will subsume the recent autorenew, so there will be no net change in expiration // The transfer will subsume the recent autorenew, so there will be no net change in expiration
// time caused by the transfer, but we must write a Cancellation. // time caused by the transfer, but we must write a Cancellation.
@ -985,8 +1032,7 @@ public class DomainTransferRequestFlowTest
.setClientId("TheRegistrar") .setClientId("TheRegistrar")
// The cancellation happens at the moment of transfer. // The cancellation happens at the moment of transfer.
.setEventTime(clock.nowUtc().plus(Registry.get("tld").getAutomaticTransferLength())) .setEventTime(clock.nowUtc().plus(Registry.get("tld").getAutomaticTransferLength()))
.setBillingTime(autorenewTime.plus( .setBillingTime(autorenewTime.plus(Registry.get("tld").getAutoRenewGracePeriodLength()))
Registry.get("tld").getAutoRenewGracePeriodLength()))
// The cancellation should refer to the old autorenew billing event. // The cancellation should refer to the old autorenew billing event.
.setRecurringEventKey(existingAutorenewEvent)); .setRecurringEventKey(existingAutorenewEvent));
} }
@ -994,14 +1040,12 @@ public class DomainTransferRequestFlowTest
@Test @Test
public void testSuccess_autorenewGraceActive_onlyAtAutomaticTransferTime() throws Exception { public void testSuccess_autorenewGraceActive_onlyAtAutomaticTransferTime() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
Key<BillingEvent.Recurring> existingAutorenewEvent = Key<BillingEvent.Recurring> existingAutorenewEvent = domain.getAutorenewBillingEvent();
domain.getAutorenewBillingEvent();
// Set domain to expire in 1 day, so that it will be in the autorenew grace period by the // Set domain to expire in 1 day, so that it will be in the autorenew grace period by the
// automatic transfer time, even though it isn't yet. // automatic transfer time, even though it isn't yet.
DateTime expirationTime = clock.nowUtc().plusDays(1); DateTime expirationTime = clock.nowUtc().plusDays(1);
domain = persistResource(domain.asBuilder() domain =
.setRegistrationExpirationTime(expirationTime) persistResource(domain.asBuilder().setRegistrationExpirationTime(expirationTime).build());
.build());
clock.advanceOneMilli(); clock.advanceOneMilli();
// The transfer will subsume the future autorenew, meaning that the expected server-approve // The transfer will subsume the future autorenew, meaning that the expected server-approve
// expiration time will be 1 year beyond the current one, and we must write a Cancellation. // expiration time will be 1 year beyond the current one, and we must write a Cancellation.
@ -1036,8 +1080,7 @@ public class DomainTransferRequestFlowTest
persistResource(Registry.get("example").asBuilder().setPremiumPriceAckRequired(false).build()); persistResource(Registry.get("example").asBuilder().setPremiumPriceAckRequired(false).build());
clock.advanceOneMilli(); clock.advanceOneMilli();
// Modify the Registrar to block premium names. // Modify the Registrar to block premium names.
persistResource( persistResource(loadRegistrar("NewRegistrar").asBuilder().setBlockPremiumNames(true).build());
loadRegistrar("NewRegistrar").asBuilder().setBlockPremiumNames(true).build());
// We don't verify the results; just check that the flow doesn't fail. // We don't verify the results; just check that the flow doesn't fail.
runTest("domain_transfer_request_premium.xml", UserPrivileges.SUPERUSER); runTest("domain_transfer_request_premium.xml", UserPrivileges.SUPERUSER);
} }
@ -1054,9 +1097,11 @@ public class DomainTransferRequestFlowTest
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
.setServerStatusChangeBillingCost(Money.of(EUR, 19)) .setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build()); .build());
assertThrows( EppException thrown =
CurrencyUnitMismatchException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee.xml", substitutions)); CurrencyUnitMismatchException.class,
() -> doFailingTest("domain_transfer_request_fee.xml", substitutions));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -1080,25 +1125,31 @@ public class DomainTransferRequestFlowTest
@Test @Test
public void testFailure_feeGivenInWrongScale_v06() throws Exception { public void testFailure_feeGivenInWrongScale_v06() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
CurrencyValueScaleException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_06_MAP)); CurrencyValueScaleException.class,
() -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_06_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception { public void testFailure_feeGivenInWrongScale_v11() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
CurrencyValueScaleException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_11_MAP)); CurrencyValueScaleException.class,
() -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_11_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception { public void testFailure_feeGivenInWrongScale_v12() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
CurrencyValueScaleException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_12_MAP)); CurrencyValueScaleException.class,
() -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_12_MAP));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
private void runWrongFeeAmountTest(Map<String, String> substitutions) throws Exception { private void runWrongFeeAmountTest(Map<String, String> substitutions) throws Exception {
@ -1107,9 +1158,11 @@ public class DomainTransferRequestFlowTest
.asBuilder() .asBuilder()
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20))) .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build()); .build());
assertThrows( EppException thrown =
FeesMismatchException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_fee.xml", substitutions)); FeesMismatchException.class,
() -> doFailingTest("domain_transfer_request_fee.xml", substitutions));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -1134,39 +1187,49 @@ public class DomainTransferRequestFlowTest
public void testFailure_premiumBlocked() throws Exception { public void testFailure_premiumBlocked() throws Exception {
setupDomain("rich", "example"); setupDomain("rich", "example");
// Modify the Registrar to block premium names. // Modify the Registrar to block premium names.
persistResource( persistResource(loadRegistrar("NewRegistrar").asBuilder().setBlockPremiumNames(true).build());
loadRegistrar("NewRegistrar").asBuilder().setBlockPremiumNames(true).build()); EppException thrown =
assertThrows( expectThrows(
PremiumNameBlockedException.class, PremiumNameBlockedException.class,
() -> doFailingTest("domain_transfer_request_premium.xml")); () -> doFailingTest("domain_transfer_request_premium.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_feeNotProvidedOnPremiumName() throws Exception { public void testFailure_feeNotProvidedOnPremiumName() throws Exception {
setupDomain("rich", "example"); setupDomain("rich", "example");
assertThrows( EppException thrown =
FeesRequiredForPremiumNameException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_premium.xml")); FeesRequiredForPremiumNameException.class,
() -> doFailingTest("domain_transfer_request_premium.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_noAuthInfo() throws Exception { public void testFailure_noAuthInfo() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
MissingTransferRequestAuthInfoException.class, expectThrows(
() -> doFailingTest("domain_transfer_request_no_authinfo.xml")); MissingTransferRequestAuthInfoException.class,
() -> doFailingTest("domain_transfer_request_no_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_badContactPassword() throws Exception { public void testFailure_badContactPassword() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
// Change the contact's password so it does not match the password in the file. // Change the contact's password so it does not match the password in the file.
contact = persistResource( contact =
contact.asBuilder() persistResource(
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) contact
.build()); .asBuilder()
assertThrows( .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
BadAuthInfoForResourceException.class, () -> doFailingTest("domain_transfer_request.xml")); .build());
EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_request.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -1175,8 +1238,11 @@ public class DomainTransferRequestFlowTest
// Set the contact to a different ROID, but don't persist it; this is just so the substitution // Set the contact to a different ROID, but don't persist it; this is just so the substitution
// code above will write the wrong ROID into the file. // code above will write the wrong ROID into the file.
contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build(); contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build();
assertThrows( EppException thrown =
BadAuthInfoForResourceException.class, () -> doFailingTest("domain_transfer_request.xml")); expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_request.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -1217,41 +1283,58 @@ public class DomainTransferRequestFlowTest
@Test @Test
public void testFailure_pending() throws Exception { public void testFailure_pending() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
domain = persistResource(domain.asBuilder() domain =
.setTransferData(domain.getTransferData().asBuilder() persistResource(
.setTransferStatus(TransferStatus.PENDING) domain
.setPendingTransferExpirationTime(clock.nowUtc().plusDays(1)) .asBuilder()
.build()) .setTransferData(
.build()); domain
assertThrows( .getTransferData()
AlreadyPendingTransferException.class, () -> doFailingTest("domain_transfer_request.xml")); .asBuilder()
.setTransferStatus(TransferStatus.PENDING)
.setPendingTransferExpirationTime(clock.nowUtc().plusDays(1))
.build())
.build());
EppException thrown =
expectThrows(
AlreadyPendingTransferException.class,
() -> doFailingTest("domain_transfer_request.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_badDomainPassword() throws Exception { public void testFailure_badDomainPassword() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
// Change the domain's password so it does not match the password in the file. // Change the domain's password so it does not match the password in the file.
domain = persistResource(domain.asBuilder() domain =
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) persistResource(
.build()); domain
assertThrows( .asBuilder()
BadAuthInfoForResourceException.class, .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
() -> doFailingTest("domain_transfer_request_domain_authinfo.xml")); .build());
EppException thrown =
expectThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_request_domain_authinfo.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_sponsoringClient() throws Exception { public void testFailure_sponsoringClient() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
setClientIdForFlow("TheRegistrar"); setClientIdForFlow("TheRegistrar");
assertThrows( EppException thrown =
ObjectAlreadySponsoredException.class, () -> doFailingTest("domain_transfer_request.xml")); expectThrows(
ObjectAlreadySponsoredException.class,
() -> doFailingTest("domain_transfer_request.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_deletedDomain() throws Exception { public void testFailure_deletedDomain() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
domain = persistResource( domain =
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
ResourceDoesNotExistException thrown = ResourceDoesNotExistException thrown =
expectThrows( expectThrows(
ResourceDoesNotExistException.class, ResourceDoesNotExistException.class,
@ -1288,15 +1371,19 @@ public class DomainTransferRequestFlowTest
@Test @Test
public void testFailure_periodInMonths() throws Exception { public void testFailure_periodInMonths() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
assertThrows( EppException thrown =
BadPeriodUnitException.class, () -> doFailingTest("domain_transfer_request_months.xml")); expectThrows(
BadPeriodUnitException.class,
() -> doFailingTest("domain_transfer_request_months.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_clientTransferProhibited() throws Exception { public void testFailure_clientTransferProhibited() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
domain = persistResource( domain =
domain.asBuilder().addStatusValue(StatusValue.CLIENT_TRANSFER_PROHIBITED).build()); persistResource(
domain.asBuilder().addStatusValue(StatusValue.CLIENT_TRANSFER_PROHIBITED).build());
ResourceStatusProhibitsOperationException thrown = ResourceStatusProhibitsOperationException thrown =
expectThrows( expectThrows(
ResourceStatusProhibitsOperationException.class, ResourceStatusProhibitsOperationException.class,
@ -1307,8 +1394,9 @@ public class DomainTransferRequestFlowTest
@Test @Test
public void testFailure_serverTransferProhibited() throws Exception { public void testFailure_serverTransferProhibited() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
domain = persistResource( domain =
domain.asBuilder().addStatusValue(StatusValue.SERVER_TRANSFER_PROHIBITED).build()); persistResource(
domain.asBuilder().addStatusValue(StatusValue.SERVER_TRANSFER_PROHIBITED).build());
ResourceStatusProhibitsOperationException thrown = ResourceStatusProhibitsOperationException thrown =
expectThrows( expectThrows(
ResourceStatusProhibitsOperationException.class, ResourceStatusProhibitsOperationException.class,
@ -1319,8 +1407,7 @@ public class DomainTransferRequestFlowTest
@Test @Test
public void testFailure_pendingDelete() throws Exception { public void testFailure_pendingDelete() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
domain = persistResource( domain = persistResource(domain.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build());
domain.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build());
ResourceStatusProhibitsOperationException thrown = ResourceStatusProhibitsOperationException thrown =
expectThrows( expectThrows(
ResourceStatusProhibitsOperationException.class, ResourceStatusProhibitsOperationException.class,