Re-add EppException marshalling assertions in domain flow tests

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=179238852
This commit is contained in:
mcilwain 2017-12-15 14:18:11 -08:00 committed by Ben McIlwain
parent 34699465d5
commit d538dca2e0
7 changed files with 1296 additions and 869 deletions

View file

@ -27,7 +27,7 @@ import static google.registry.testing.DatastoreHelper.persistDeletedDomain;
import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource;
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.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
@ -39,6 +39,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.EppException.UnimplementedExtensionException;
import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@ -71,8 +72,8 @@ import org.junit.Before;
import org.junit.Test;
/** Unit tests for {@link DomainRestoreRequestFlow}. */
public class DomainRestoreRequestFlowTest extends
ResourceFlowTestCase<DomainRestoreRequestFlow, DomainResource> {
public class DomainRestoreRequestFlowTest
extends ResourceFlowTestCase<DomainRestoreRequestFlow, DomainResource> {
private static final ImmutableMap<String, String> FEE_06_MAP =
ImmutableMap.of("FEE_VERSION", "0.6", "FEE_NS", "fee");
@ -92,24 +93,31 @@ public class DomainRestoreRequestFlowTest extends
void persistPendingDeleteDomain() throws Exception {
DomainResource domain = newDomainResource(getUniqueIdFromCommand());
HistoryEntry historyEntry = persistResource(
new HistoryEntry.Builder()
.setType(HistoryEntry.Type.DOMAIN_DELETE)
.setParent(domain)
.build());
domain = persistResource(domain.asBuilder()
.setRegistrationExpirationTime(clock.nowUtc().plusYears(5).plusDays(45))
.setDeletionTime(clock.nowUtc().plusDays(35))
.addGracePeriod(GracePeriod.create(
GracePeriodStatus.REDEMPTION, clock.nowUtc().plusDays(1), "foo", null))
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.setDeletePollMessage(Key.create(persistResource(
new PollMessage.OneTime.Builder()
.setClientId("TheRegistrar")
.setEventTime(clock.nowUtc().plusDays(5))
.setParent(historyEntry)
.build())))
.build());
HistoryEntry historyEntry =
persistResource(
new HistoryEntry.Builder()
.setType(HistoryEntry.Type.DOMAIN_DELETE)
.setParent(domain)
.build());
domain =
persistResource(
domain
.asBuilder()
.setRegistrationExpirationTime(clock.nowUtc().plusYears(5).plusDays(45))
.setDeletionTime(clock.nowUtc().plusDays(35))
.addGracePeriod(
GracePeriod.create(
GracePeriodStatus.REDEMPTION, clock.nowUtc().plusDays(1), "foo", null))
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.setDeletePollMessage(
Key.create(
persistResource(
new PollMessage.OneTime.Builder()
.setClientId("TheRegistrar")
.setEventTime(clock.nowUtc().plusDays(5))
.setParent(historyEntry)
.build())))
.build());
clock.advanceOneMilli();
}
@ -126,22 +134,24 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain();
assertTransactionalFlow(true);
// Double check that we see a poll message in the future for when the delete happens.
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1)))
.hasSize(1);
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusMonths(1))).hasSize(1);
runFlowAssertResponse(loadFile("domain_update_response.xml"));
DomainResource domain = reloadResourceByForeignKey();
HistoryEntry historyEntryDomainRestore =
getOnlyHistoryEntryOfType(domain, HistoryEntry.Type.DOMAIN_RESTORE);
assertThat(ofy().load().key(domain.getAutorenewBillingEvent()).now().getEventTime())
.isEqualTo(clock.nowUtc().plusYears(1));
assertAboutDomains().that(domain)
assertAboutDomains()
.that(domain)
// New expiration time should be exactly a year from now.
.hasRegistrationExpirationTime(clock.nowUtc().plusYears(1)).and()
.doesNotHaveStatusValue(StatusValue.PENDING_DELETE).and()
.hasDeletionTime(END_OF_TIME).and()
.hasRegistrationExpirationTime(clock.nowUtc().plusYears(1))
.and()
.doesNotHaveStatusValue(StatusValue.PENDING_DELETE)
.and()
.hasDeletionTime(END_OF_TIME)
.and()
.hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.DOMAIN_DELETE,
HistoryEntry.Type.DOMAIN_RESTORE);
HistoryEntry.Type.DOMAIN_DELETE, HistoryEntry.Type.DOMAIN_RESTORE);
assertThat(domain.getGracePeriods()).isEmpty();
assertDnsTasksEnqueued("example.tld");
// The poll message for the delete should now be gone. The only poll message should be the new
@ -209,6 +219,7 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain();
runFlowAssertResponse(loadFile("domain_update_restore_request_response_fee.xml", FEE_12_MAP));
}
@Test
public void testSuccess_fee_withDefaultAttributes_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_defaults.xml", FEE_06_MAP);
@ -234,63 +245,72 @@ public class DomainRestoreRequestFlowTest extends
public void testFailure_refundableFee_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_06_MAP);
persistPendingDeleteDomain();
assertThrows(UnsupportedFeeAttributeException.class, this::runFlow);
EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_refundableFee_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_11_MAP);
persistPendingDeleteDomain();
assertThrows(UnsupportedFeeAttributeException.class, this::runFlow);
EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_refundableFee_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_12_MAP);
persistPendingDeleteDomain();
assertThrows(UnsupportedFeeAttributeException.class, this::runFlow);
EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_gracePeriodFee_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_06_MAP);
persistPendingDeleteDomain();
assertThrows(UnsupportedFeeAttributeException.class, this::runFlow);
EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_gracePeriodFee_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_11_MAP);
persistPendingDeleteDomain();
assertThrows(UnsupportedFeeAttributeException.class, this::runFlow);
EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_gracePeriodFee_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_12_MAP);
persistPendingDeleteDomain();
assertThrows(UnsupportedFeeAttributeException.class, this::runFlow);
EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_appliedFee_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_06_MAP);
persistPendingDeleteDomain();
assertThrows(UnsupportedFeeAttributeException.class, this::runFlow);
EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_appliedFee_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_11_MAP);
persistPendingDeleteDomain();
assertThrows(UnsupportedFeeAttributeException.class, this::runFlow);
EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_appliedFee_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_12_MAP);
persistPendingDeleteDomain();
assertThrows(UnsupportedFeeAttributeException.class, this::runFlow);
EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -311,9 +331,7 @@ public class DomainRestoreRequestFlowTest extends
.build());
persistPendingDeleteDomain();
runFlowAssertResponse(
CommitMode.LIVE,
UserPrivileges.SUPERUSER,
loadFile("domain_update_response.xml"));
CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_update_response.xml"));
}
@Test
@ -323,12 +341,9 @@ public class DomainRestoreRequestFlowTest extends
setEppInput("domain_update_restore_request_premium.xml");
persistPendingDeleteDomain();
// Modify the Registrar to block premium names.
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build());
persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build());
runFlowAssertResponse(
CommitMode.LIVE,
UserPrivileges.SUPERUSER,
loadFile("domain_update_response.xml"));
CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_update_response.xml"));
}
@Test
@ -344,7 +359,8 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain();
persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
assertThrows(FeesMismatchException.class, this::runFlow);
EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -353,7 +369,8 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain();
persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
assertThrows(FeesMismatchException.class, this::runFlow);
EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -362,7 +379,8 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain();
persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
assertThrows(FeesMismatchException.class, this::runFlow);
EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
private void runWrongCurrencyTest(Map<String, String> substitutions) throws Exception {
@ -378,7 +396,8 @@ public class DomainRestoreRequestFlowTest extends
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
assertThrows(CurrencyUnitMismatchException.class, this::runFlow);
EppException thrown = expectThrows(CurrencyUnitMismatchException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -400,21 +419,24 @@ public class DomainRestoreRequestFlowTest extends
public void testFailure_feeGivenInWrongScale_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_06_MAP);
persistPendingDeleteDomain();
assertThrows(CurrencyValueScaleException.class, this::runFlow);
EppException thrown = expectThrows(CurrencyValueScaleException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_11_MAP);
persistPendingDeleteDomain();
assertThrows(CurrencyValueScaleException.class, this::runFlow);
EppException thrown = expectThrows(CurrencyValueScaleException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_12_MAP);
persistPendingDeleteDomain();
assertThrows(CurrencyValueScaleException.class, this::runFlow);
EppException thrown = expectThrows(CurrencyValueScaleException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -425,63 +447,73 @@ public class DomainRestoreRequestFlowTest extends
.setDeletionTime(clock.nowUtc().plusDays(4))
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.build());
assertThrows(DomainNotEligibleForRestoreException.class, this::runFlow);
EppException thrown = expectThrows(DomainNotEligibleForRestoreException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_notDeleted() throws Exception {
persistActiveDomain(getUniqueIdFromCommand());
assertThrows(DomainNotEligibleForRestoreException.class, this::runFlow);
EppException thrown = expectThrows(DomainNotEligibleForRestoreException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_fullyDeleted() throws Exception {
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
assertThrows(ResourceDoesNotExistException.class, this::runFlow);
EppException thrown = expectThrows(ResourceDoesNotExistException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_withChange() throws Exception {
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_change.xml");
assertThrows(RestoreCommandIncludesChangesException.class, this::runFlow);
EppException thrown = expectThrows(RestoreCommandIncludesChangesException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_withAdd() throws Exception {
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_add.xml");
assertThrows(RestoreCommandIncludesChangesException.class, this::runFlow);
EppException thrown = expectThrows(RestoreCommandIncludesChangesException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_withRemove() throws Exception {
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_remove.xml");
assertThrows(RestoreCommandIncludesChangesException.class, this::runFlow);
EppException thrown = expectThrows(RestoreCommandIncludesChangesException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_withSecDnsExtension() throws Exception {
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_secdns.xml");
assertThrows(UnimplementedExtensionException.class, this::runFlow);
EppException thrown = expectThrows(UnimplementedExtensionException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistPendingDeleteDomain();
assertThrows(ResourceNotOwnedException.class, this::runFlow);
EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
public void testSuccess_superuserUnauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistPendingDeleteDomain();
assertThrows(
ResourceNotOwnedException.class,
() -> runFlowAssertResponse(loadFile("domain_update_response.xml")));
EppException thrown =
expectThrows(
ResourceNotOwnedException.class,
() -> runFlowAssertResponse(loadFile("domain_update_response.xml")));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -489,7 +521,8 @@ public class DomainRestoreRequestFlowTest extends
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistPendingDeleteDomain();
assertThrows(NotAuthorizedForTldException.class, this::runFlow);
EppException thrown = expectThrows(NotAuthorizedForTldException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -508,7 +541,8 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain();
// Modify the Registrar to block premium names.
persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build());
assertThrows(PremiumNameBlockedException.class, this::runFlow);
EppException thrown = expectThrows(PremiumNameBlockedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -520,7 +554,8 @@ public class DomainRestoreRequestFlowTest extends
.setReservedLists(persistReservedList("tld-reserved", "example,FULLY_BLOCKED"))
.build());
persistPendingDeleteDomain();
assertThrows(DomainReservedException.class, this::runFlow);
EppException thrown = expectThrows(DomainReservedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -528,7 +563,8 @@ public class DomainRestoreRequestFlowTest extends
createTld("example");
setEppInput("domain_update_restore_request_premium.xml");
persistPendingDeleteDomain();
assertThrows(FeesRequiredForPremiumNameException.class, this::runFlow);
EppException thrown = expectThrows(FeesRequiredForPremiumNameException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@ -537,7 +573,7 @@ public class DomainRestoreRequestFlowTest extends
runFlow();
assertIcannReportingActivityFieldLogged("srs-dom-rgp-restore-request");
assertTldsFieldLogged("tld");
}
}
@Test
public void testIcannTransactionReportField_getsStored() throws Exception {