mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 08:27:14 +02:00
Automatically refactor more exception testing to use new JUnit rules
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=179072309
This commit is contained in:
parent
d5d29959b4
commit
9157930983
100 changed files with 3900 additions and 3192 deletions
|
@ -27,6 +27,8 @@ 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.JUnitBackports.expectThrows;
|
||||
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
|
@ -232,72 +234,63 @@ public class DomainRestoreRequestFlowTest extends
|
|||
public void testFailure_refundableFee_v06() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_06_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(UnsupportedFeeAttributeException.class);
|
||||
runFlow();
|
||||
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_refundableFee_v11() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_11_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(UnsupportedFeeAttributeException.class);
|
||||
runFlow();
|
||||
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_refundableFee_v12() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_12_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(UnsupportedFeeAttributeException.class);
|
||||
runFlow();
|
||||
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_gracePeriodFee_v06() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_06_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(UnsupportedFeeAttributeException.class);
|
||||
runFlow();
|
||||
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_gracePeriodFee_v11() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_11_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(UnsupportedFeeAttributeException.class);
|
||||
runFlow();
|
||||
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_gracePeriodFee_v12() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_12_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(UnsupportedFeeAttributeException.class);
|
||||
runFlow();
|
||||
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_appliedFee_v06() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_06_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(UnsupportedFeeAttributeException.class);
|
||||
runFlow();
|
||||
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_appliedFee_v11() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_11_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(UnsupportedFeeAttributeException.class);
|
||||
runFlow();
|
||||
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_appliedFee_v12() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_12_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(UnsupportedFeeAttributeException.class);
|
||||
runFlow();
|
||||
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -340,9 +333,9 @@ public class DomainRestoreRequestFlowTest extends
|
|||
|
||||
@Test
|
||||
public void testFailure_doesNotExist() throws Exception {
|
||||
thrown.expect(ResourceDoesNotExistException.class);
|
||||
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
|
||||
runFlow();
|
||||
ResourceDoesNotExistException thrown =
|
||||
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
|
||||
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -351,8 +344,7 @@ public class DomainRestoreRequestFlowTest extends
|
|||
persistPendingDeleteDomain();
|
||||
persistResource(
|
||||
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
|
||||
thrown.expect(FeesMismatchException.class);
|
||||
runFlow();
|
||||
assertThrows(FeesMismatchException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -361,8 +353,7 @@ public class DomainRestoreRequestFlowTest extends
|
|||
persistPendingDeleteDomain();
|
||||
persistResource(
|
||||
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
|
||||
thrown.expect(FeesMismatchException.class);
|
||||
runFlow();
|
||||
assertThrows(FeesMismatchException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -371,8 +362,7 @@ public class DomainRestoreRequestFlowTest extends
|
|||
persistPendingDeleteDomain();
|
||||
persistResource(
|
||||
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
|
||||
thrown.expect(FeesMismatchException.class);
|
||||
runFlow();
|
||||
assertThrows(FeesMismatchException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
private void runWrongCurrencyTest(Map<String, String> substitutions) throws Exception {
|
||||
|
@ -388,8 +378,7 @@ public class DomainRestoreRequestFlowTest extends
|
|||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
||||
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
|
||||
.build());
|
||||
thrown.expect(CurrencyUnitMismatchException.class);
|
||||
runFlow();
|
||||
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -411,24 +400,21 @@ public class DomainRestoreRequestFlowTest extends
|
|||
public void testFailure_feeGivenInWrongScale_v06() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_06_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(CurrencyValueScaleException.class);
|
||||
runFlow();
|
||||
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_feeGivenInWrongScale_v11() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_11_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(CurrencyValueScaleException.class);
|
||||
runFlow();
|
||||
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_feeGivenInWrongScale_v12() throws Exception {
|
||||
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_12_MAP);
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(CurrencyValueScaleException.class);
|
||||
runFlow();
|
||||
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -439,70 +425,63 @@ public class DomainRestoreRequestFlowTest extends
|
|||
.setDeletionTime(clock.nowUtc().plusDays(4))
|
||||
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
|
||||
.build());
|
||||
thrown.expect(DomainNotEligibleForRestoreException.class);
|
||||
runFlow();
|
||||
assertThrows(DomainNotEligibleForRestoreException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_notDeleted() throws Exception {
|
||||
persistActiveDomain(getUniqueIdFromCommand());
|
||||
thrown.expect(DomainNotEligibleForRestoreException.class);
|
||||
runFlow();
|
||||
assertThrows(DomainNotEligibleForRestoreException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_fullyDeleted() throws Exception {
|
||||
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
thrown.expect(ResourceDoesNotExistException.class);
|
||||
runFlow();
|
||||
assertThrows(ResourceDoesNotExistException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_withChange() throws Exception {
|
||||
persistPendingDeleteDomain();
|
||||
setEppInput("domain_update_restore_request_with_change.xml");
|
||||
thrown.expect(RestoreCommandIncludesChangesException.class);
|
||||
runFlow();
|
||||
assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_withAdd() throws Exception {
|
||||
persistPendingDeleteDomain();
|
||||
setEppInput("domain_update_restore_request_with_add.xml");
|
||||
thrown.expect(RestoreCommandIncludesChangesException.class);
|
||||
runFlow();
|
||||
assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_withRemove() throws Exception {
|
||||
persistPendingDeleteDomain();
|
||||
setEppInput("domain_update_restore_request_with_remove.xml");
|
||||
thrown.expect(RestoreCommandIncludesChangesException.class);
|
||||
runFlow();
|
||||
assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_withSecDnsExtension() throws Exception {
|
||||
persistPendingDeleteDomain();
|
||||
setEppInput("domain_update_restore_request_with_secdns.xml");
|
||||
thrown.expect(UnimplementedExtensionException.class);
|
||||
runFlow();
|
||||
assertThrows(UnimplementedExtensionException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_unauthorizedClient() throws Exception {
|
||||
sessionMetadata.setClientId("NewRegistrar");
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(ResourceNotOwnedException.class);
|
||||
runFlow();
|
||||
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_superuserUnauthorizedClient() throws Exception {
|
||||
sessionMetadata.setClientId("NewRegistrar");
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(ResourceNotOwnedException.class);
|
||||
runFlowAssertResponse(loadFile("domain_update_response.xml"));
|
||||
assertThrows(
|
||||
ResourceNotOwnedException.class,
|
||||
() -> runFlowAssertResponse(loadFile("domain_update_response.xml")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -510,8 +489,7 @@ public class DomainRestoreRequestFlowTest extends
|
|||
persistResource(
|
||||
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(NotAuthorizedForTldException.class);
|
||||
runFlow();
|
||||
assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -530,8 +508,7 @@ public class DomainRestoreRequestFlowTest extends
|
|||
persistPendingDeleteDomain();
|
||||
// Modify the Registrar to block premium names.
|
||||
persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build());
|
||||
thrown.expect(PremiumNameBlockedException.class);
|
||||
runFlow();
|
||||
assertThrows(PremiumNameBlockedException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -543,8 +520,7 @@ public class DomainRestoreRequestFlowTest extends
|
|||
.setReservedLists(persistReservedList("tld-reserved", "example,FULLY_BLOCKED"))
|
||||
.build());
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(DomainReservedException.class);
|
||||
runFlow();
|
||||
assertThrows(DomainReservedException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -552,8 +528,7 @@ public class DomainRestoreRequestFlowTest extends
|
|||
createTld("example");
|
||||
setEppInput("domain_update_restore_request_premium.xml");
|
||||
persistPendingDeleteDomain();
|
||||
thrown.expect(FeesRequiredForPremiumNameException.class);
|
||||
runFlow();
|
||||
assertThrows(FeesRequiredForPremiumNameException.class, () -> runFlow());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue