diff --git a/javatests/google/registry/dns/writer/dnsupdate/DnsMessageTransportTest.java b/javatests/google/registry/dns/writer/dnsupdate/DnsMessageTransportTest.java index e30f68dea..04c63b1ff 100644 --- a/javatests/google/registry/dns/writer/dnsupdate/DnsMessageTransportTest.java +++ b/javatests/google/registry/dns/writer/dnsupdate/DnsMessageTransportTest.java @@ -120,8 +120,7 @@ public class DnsMessageTransportTest { when(mockSocket.getOutputStream()).thenReturn(new ByteArrayOutputStream()); thrown.expect(EOFException.class); - Message expectedQuery = new Message(); - resolver.send(expectedQuery); + resolver.send(new Message()); } @Test diff --git a/javatests/google/registry/export/DatastoreBackupInfoTest.java b/javatests/google/registry/export/DatastoreBackupInfoTest.java index a10fad4c0..cd805a238 100644 --- a/javatests/google/registry/export/DatastoreBackupInfoTest.java +++ b/javatests/google/registry/export/DatastoreBackupInfoTest.java @@ -105,29 +105,29 @@ public class DatastoreBackupInfoTest { @Test public void testFailure_missingName() throws Exception { - thrown.expect(NullPointerException.class); backupEntity.removeProperty("name"); + thrown.expect(NullPointerException.class); new DatastoreBackupInfo(persistEntity(backupEntity)); } @Test public void testFailure_missingKinds() throws Exception { - thrown.expect(NullPointerException.class); backupEntity.removeProperty("kinds"); + thrown.expect(NullPointerException.class); new DatastoreBackupInfo(persistEntity(backupEntity)); } @Test public void testFailure_missingStartTime() throws Exception { - thrown.expect(NullPointerException.class); backupEntity.removeProperty("start_time"); + thrown.expect(NullPointerException.class); new DatastoreBackupInfo(persistEntity(backupEntity)); } @Test public void testFailure_badGcsFilenameFormat() throws Exception { - thrown.expect(IllegalArgumentException.class); backupEntity.setProperty("gs_handle", new Text("foo")); + thrown.expect(IllegalArgumentException.class); new DatastoreBackupInfo(persistEntity(backupEntity)); } } diff --git a/javatests/google/registry/export/ExportDomainListsActionTest.java b/javatests/google/registry/export/ExportDomainListsActionTest.java index 14720650a..1d9133933 100644 --- a/javatests/google/registry/export/ExportDomainListsActionTest.java +++ b/javatests/google/registry/export/ExportDomainListsActionTest.java @@ -16,6 +16,7 @@ package google.registry.export; import static com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication; @@ -31,13 +32,11 @@ import com.google.appengine.tools.cloudstorage.ListResult; import com.google.common.base.Splitter; import google.registry.model.registry.Registry; import google.registry.model.registry.Registry.TldType; -import google.registry.testing.ExceptionRule; import google.registry.testing.FakeResponse; import google.registry.testing.mapreduce.MapreduceTestCase; import java.io.FileNotFoundException; import org.joda.time.DateTime; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -48,9 +47,6 @@ public class ExportDomainListsActionTest extends MapreduceTestCase exception) throws Exception { - thrown.expect(exception); persistResource( newContactResource(getUniqueIdFromCommand()).asBuilder() .setStatusValues(ImmutableSet.of(statusValue)) .build()); + thrown.expect(exception); runFlow(); } @@ -85,10 +85,10 @@ public class ContactDeleteFlowTest @Test public void testFailure_existedButWasDeleted() throws Exception { + persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); thrown.expect( ResourceDoesNotExistException.class, String.format("(%s)", getUniqueIdFromCommand())); - persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); runFlow(); } @@ -112,9 +112,9 @@ public class ContactDeleteFlowTest @Test public void testFailure_unauthorizedClient() throws Exception { - thrown.expect(ResourceNotOwnedException.class); sessionMetadata.setClientId("NewRegistrar"); persistActiveContact(getUniqueIdFromCommand()); + thrown.expect(ResourceNotOwnedException.class); runFlow(); } diff --git a/javatests/google/registry/flows/contact/ContactInfoFlowTest.java b/javatests/google/registry/flows/contact/ContactInfoFlowTest.java index 088e8b054..5481dc6f7 100644 --- a/javatests/google/registry/flows/contact/ContactInfoFlowTest.java +++ b/javatests/google/registry/flows/contact/ContactInfoFlowTest.java @@ -171,10 +171,10 @@ public class ContactInfoFlowTest extends ResourceFlowTestCaseof()) .build()); + thrown.expect(NotAuthorizedForTldException.class); runFlow(); } diff --git a/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java b/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java index 9f408c3ee..4805df8c8 100644 --- a/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java @@ -487,13 +487,13 @@ public class DomainAllocateFlowTest @Test public void testFailure_notAuthorizedForTld() throws Exception { - thrown.expect(NotAuthorizedForTldException.class); setupDomainApplication("tld", TldState.QUIET_PERIOD); DatastoreHelper.persistResource( Registrar.loadByClientId("TheRegistrar") .asBuilder() .setAllowedTlds(ImmutableSet.of()) .build()); + thrown.expect(NotAuthorizedForTldException.class); runFlow(); } @@ -502,8 +502,8 @@ public class DomainAllocateFlowTest setupDomainApplication("tld", TldState.GENERAL_AVAILABILITY); clock.advanceOneMilli(); setEppInput("domain_allocate_no_nameservers.xml"); - thrown.expect(OnlySuperuserCanAllocateException.class); assertTransactionalFlow(true); + thrown.expect(OnlySuperuserCanAllocateException.class); runFlow(CommitMode.LIVE, UserPrivileges.NORMAL); } } diff --git a/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java index 61ec265a1..62470d5bd 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java @@ -17,6 +17,7 @@ package google.registry.flows.domain; import static com.google.common.collect.Iterables.getLast; import static com.google.common.io.BaseEncoding.base16; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; @@ -30,6 +31,7 @@ import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; +import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME; import static org.joda.money.CurrencyUnit.EUR; @@ -961,7 +963,6 @@ public class DomainApplicationCreateFlowTest @Test public void testFailure_landrushLrpApplication_usedToken() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); createTld("tld", TldState.LANDRUSH); persistResource(Registry.get("tld").asBuilder() .setLrpTldStates(ImmutableSet.of(TldState.LANDRUSH)) @@ -975,6 +976,7 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_lrp.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); + thrown.expect(BadAuthInfoForResourceException.class); runFlow(); } @@ -1514,14 +1516,12 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); persistActiveDomain(getUniqueIdFromCommand()); try { - // This fails fast and throws DomainAlreadyExistsException from init() as a special case. - thrown.expect( - ResourceAlreadyExistsException.class, - String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); runFlow(); + assertWithMessage("Expected ResourceAlreadyExistsException to be thrown").fail(); } catch (ResourceAlreadyExistsException e) { assertThat(e.isFailfast()).isTrue(); - throw e; + assertAboutEppExceptions().that(e).marshalsToXml().and().hasMessage( + String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); } } @@ -1583,15 +1583,13 @@ public class DomainApplicationCreateFlowTest persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder() .addGracePeriod(GracePeriod.create(gracePeriodStatus, END_OF_TIME, "", null)) .build()); - // This doesn't fail fast, so it throws the regular ResourceAlreadyExistsException from run(). - thrown.expect( - ResourceAlreadyExistsException.class, - String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); try { runFlow(); + assertWithMessage("Expected ResourceAlreadyExistsException to be thrown").fail(); } catch (ResourceAlreadyExistsException e) { assertThat(e.isFailfast()).isFalse(); - throw e; + assertAboutEppExceptions().that(e).marshalsToXml().and().hasMessage( + String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); } } diff --git a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java index 8ff1672b9..a3bb1ff8d 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java @@ -127,28 +127,27 @@ public class DomainApplicationDeleteFlowTest @Test public void testFailure_existedButWasDeleted() throws Exception { - thrown.expect( - ResourceDoesNotExistException.class, - String.format("(%s)", getUniqueIdFromCommand())); persistResource(newDomainApplication("example.tld").asBuilder() .setRepoId("1-TLD") .setDeletionTime(clock.nowUtc().minusSeconds(1)) .build()); + thrown.expect( + ResourceDoesNotExistException.class, + String.format("(%s)", getUniqueIdFromCommand())); runFlow(); } @Test public void testFailure_unauthorizedClient() throws Exception { - thrown.expect(ResourceNotOwnedException.class); sessionMetadata.setClientId("NewRegistrar"); persistResource( newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + thrown.expect(ResourceNotOwnedException.class); runFlow(); } @Test public void testFailure_notAuthorizedForTld() throws Exception { - thrown.expect(NotAuthorizedForTldException.class); persistResource( newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); persistResource( @@ -156,6 +155,7 @@ public class DomainApplicationDeleteFlowTest .asBuilder() .setAllowedTlds(ImmutableSet.of()) .build()); + thrown.expect(NotAuthorizedForTldException.class); runFlow(); } @@ -173,12 +173,12 @@ public class DomainApplicationDeleteFlowTest public void testFailure_sunriseDuringLandrush() throws Exception { createTld("tld", TldState.LANDRUSH); setEppInput("domain_delete_application_landrush.xml"); - thrown.expect(SunriseApplicationCannotBeDeletedInLandrushException.class); persistResource(newDomainApplication("example.tld") .asBuilder() .setRepoId("1-TLD") .setPhase(LaunchPhase.SUNRISE) .build()); + thrown.expect(SunriseApplicationCannotBeDeletedInLandrushException.class); runFlow(); } @@ -222,45 +222,45 @@ public class DomainApplicationDeleteFlowTest @Test public void testFailure_mismatchedPhase() throws Exception { - thrown.expect(LaunchPhaseMismatchException.class); setEppInput("domain_delete_application_landrush.xml"); persistResource( newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + thrown.expect(LaunchPhaseMismatchException.class); runFlow(); } @Test public void testFailure_wrongExtension() throws Exception { - thrown.expect(UnimplementedExtensionException.class); setEppInput("domain_delete_application_wrong_extension.xml"); persistActiveDomainApplication("example.tld"); + thrown.expect(UnimplementedExtensionException.class); runFlow(); } @Test public void testFailure_predelegation() throws Exception { - thrown.expect(BadCommandForRegistryPhaseException.class); createTld("tld", TldState.PREDELEGATION); persistResource( newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + thrown.expect(BadCommandForRegistryPhaseException.class); runFlow(); } @Test public void testFailure_quietPeriod() throws Exception { - thrown.expect(BadCommandForRegistryPhaseException.class); createTld("tld", TldState.QUIET_PERIOD); persistResource( newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + thrown.expect(BadCommandForRegistryPhaseException.class); runFlow(); } @Test public void testFailure_generalAvailability() throws Exception { - thrown.expect(BadCommandForRegistryPhaseException.class); createTld("tld", TldState.GENERAL_AVAILABILITY); persistResource( newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + thrown.expect(BadCommandForRegistryPhaseException.class); runFlow(); } @@ -296,9 +296,9 @@ public class DomainApplicationDeleteFlowTest @Test public void testFailure_applicationIdForDifferentDomain() throws Exception { - thrown.expect(ApplicationDomainNameMismatchException.class); persistResource( newDomainApplication("invalid.tld").asBuilder().setRepoId("1-TLD").build()); + thrown.expect(ApplicationDomainNameMismatchException.class); runFlow(); } } diff --git a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java index 32e86fbac..2332f47c4 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java @@ -268,54 +268,54 @@ public class DomainApplicationInfoFlowTest @Test public void testFailure_existedButWasDeleted() throws Exception { - thrown.expect( - ResourceDoesNotExistException.class, - String.format("(%s)", getUniqueIdFromCommand())); persistResource(new DomainApplication.Builder() .setRepoId("123-COM") .setFullyQualifiedDomainName("timber.com") .setDeletionTime(clock.nowUtc().minusDays(1)) .setRegistrant(Key.create(persistActiveContact("jd1234"))) .build()); + thrown.expect( + ResourceDoesNotExistException.class, + String.format("(%s)", getUniqueIdFromCommand())); runFlow(); } @Test public void testFailure_unauthorized() throws Exception { - thrown.expect(ResourceNotOwnedException.class); persistResource( AppEngineRule.makeRegistrar1().asBuilder().setClientId("ClientZ").build()); sessionMetadata.setClientId("ClientZ"); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); + thrown.expect(ResourceNotOwnedException.class); runFlow(); } @Test public void testFailure_applicationIdForDifferentDomain() throws Exception { - thrown.expect(ApplicationDomainNameMismatchException.class); persistResource(new DomainApplication.Builder() .setRepoId("123-TLD") .setFullyQualifiedDomainName("invalid.tld") .setRegistrant(Key.create(persistActiveContact("jd1234"))) .setPhase(LaunchPhase.SUNRUSH) .build()); + thrown.expect(ApplicationDomainNameMismatchException.class); runFlow(); } @Test public void testFailure_noApplicationId() throws Exception { - thrown.expect(MissingApplicationIdException.class); setEppInput("domain_info_sunrise_no_application_id.xml"); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); + thrown.expect(MissingApplicationIdException.class); runFlow(); } @Test public void testFailure_mismatchedLaunchPhase() throws Exception { - thrown.expect(ApplicationLaunchPhaseMismatchException.class); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); application = persistResource( application.asBuilder().setPhase(LaunchPhase.SUNRISE).build()); + thrown.expect(ApplicationLaunchPhaseMismatchException.class); runFlow(); } } diff --git a/javatests/google/registry/flows/domain/DomainCheckFlowTest.java b/javatests/google/registry/flows/domain/DomainCheckFlowTest.java index e60f54f14..cf1fb09b4 100644 --- a/javatests/google/registry/flows/domain/DomainCheckFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainCheckFlowTest.java @@ -266,12 +266,12 @@ public class DomainCheckFlowTest @Test public void testFailure_notAuthorizedForTld() throws Exception { - thrown.expect(NotAuthorizedForTldException.class); DatastoreHelper.persistResource( Registrar.loadByClientId("TheRegistrar") .asBuilder() .setAllowedTlds(ImmutableSet.of()) .build()); + thrown.expect(NotAuthorizedForTldException.class); runFlow(); } @@ -625,156 +625,156 @@ public class DomainCheckFlowTest @Test public void testFeeExtension_wrongCurrency_v06() throws Exception { - thrown.expect(CurrencyUnitMismatchException.class); setEppInput("domain_check_fee_euro_v06.xml"); + thrown.expect(CurrencyUnitMismatchException.class); runFlow(); } @Test public void testFeeExtension_wrongCurrency_v11() throws Exception { - thrown.expect(CurrencyUnitMismatchException.class); setEppInput("domain_check_fee_euro_v11.xml"); + thrown.expect(CurrencyUnitMismatchException.class); runFlow(); } @Test public void testFeeExtension_wrongCurrency_v12() throws Exception { - thrown.expect(CurrencyUnitMismatchException.class); setEppInput("domain_check_fee_euro_v12.xml"); + thrown.expect(CurrencyUnitMismatchException.class); runFlow(); } @Test public void testFeeExtension_periodNotInYears_v06() throws Exception { - thrown.expect(BadPeriodUnitException.class); setEppInput("domain_check_fee_bad_period_v06.xml"); + thrown.expect(BadPeriodUnitException.class); runFlow(); } @Test public void testFeeExtension_periodNotInYears_v11() throws Exception { - thrown.expect(BadPeriodUnitException.class); setEppInput("domain_check_fee_bad_period_v11.xml"); + thrown.expect(BadPeriodUnitException.class); runFlow(); } @Test public void testFeeExtension_periodNotInYears_v12() throws Exception { - thrown.expect(BadPeriodUnitException.class); setEppInput("domain_check_fee_bad_period_v12.xml"); + thrown.expect(BadPeriodUnitException.class); runFlow(); } @Test public void testFeeExtension_commandWithPhase_v06() throws Exception { - thrown.expect(FeeChecksDontSupportPhasesException.class); setEppInput("domain_check_fee_command_phase_v06.xml"); + thrown.expect(FeeChecksDontSupportPhasesException.class); runFlow(); } @Test public void testFeeExtension_commandWithPhase_v11() throws Exception { - thrown.expect(FeeChecksDontSupportPhasesException.class); setEppInput("domain_check_fee_command_phase_v11.xml"); + thrown.expect(FeeChecksDontSupportPhasesException.class); runFlow(); } @Test public void testFeeExtension_commandWithPhase_v12() throws Exception { - thrown.expect(FeeChecksDontSupportPhasesException.class); setEppInput("domain_check_fee_command_phase_v12.xml"); + thrown.expect(FeeChecksDontSupportPhasesException.class); runFlow(); } @Test public void testFeeExtension_commandSubphase_v06() throws Exception { - thrown.expect(FeeChecksDontSupportPhasesException.class); setEppInput("domain_check_fee_command_subphase_v06.xml"); + thrown.expect(FeeChecksDontSupportPhasesException.class); runFlow(); } @Test public void testFeeExtension_commandSubphase_v11() throws Exception { - thrown.expect(FeeChecksDontSupportPhasesException.class); setEppInput("domain_check_fee_command_subphase_v11.xml"); + thrown.expect(FeeChecksDontSupportPhasesException.class); runFlow(); } @Test public void testFeeExtension_commandSubphase_v12() throws Exception { - thrown.expect(FeeChecksDontSupportPhasesException.class); setEppInput("domain_check_fee_command_subphase_v12.xml"); + thrown.expect(FeeChecksDontSupportPhasesException.class); runFlow(); } // This test is only relevant for v06, since domain names are not specified in v11 or v12. @Test public void testFeeExtension_feeCheckNotInAvailabilityCheck() throws Exception { - thrown.expect(OnlyCheckedNamesCanBeFeeCheckedException.class); setEppInput("domain_check_fee_not_in_avail.xml"); + thrown.expect(OnlyCheckedNamesCanBeFeeCheckedException.class); runFlow(); } @Test public void testFeeExtension_multiyearRestore_v06() throws Exception { - thrown.expect(RestoresAreAlwaysForOneYearException.class); setEppInput("domain_check_fee_multiyear_restore_v06.xml"); + thrown.expect(RestoresAreAlwaysForOneYearException.class); runFlow(); } @Test public void testFeeExtension_multiyearRestore_v11() throws Exception { - thrown.expect(RestoresAreAlwaysForOneYearException.class); setEppInput("domain_check_fee_multiyear_restore_v11.xml"); + thrown.expect(RestoresAreAlwaysForOneYearException.class); runFlow(); } @Test public void testFeeExtension_multiyearRestore_v12() throws Exception { - thrown.expect(RestoresAreAlwaysForOneYearException.class); setEppInput("domain_check_fee_multiyear_restore_v12.xml"); + thrown.expect(RestoresAreAlwaysForOneYearException.class); runFlow(); } @Test public void testFeeExtension_unknownCommand_v06() throws Exception { - thrown.expect(UnknownFeeCommandException.class); setEppInput("domain_check_fee_unknown_command_v06.xml"); + thrown.expect(UnknownFeeCommandException.class); runFlow(); } @Test public void testFeeExtension_unknownCommand_v11() throws Exception { - thrown.expect(UnknownFeeCommandException.class); setEppInput("domain_check_fee_unknown_command_v11.xml"); + thrown.expect(UnknownFeeCommandException.class); runFlow(); } @Test public void testFeeExtension_unknownCommand_v12() throws Exception { - thrown.expect(UnknownFeeCommandException.class); setEppInput("domain_check_fee_unknown_command_v12.xml"); + thrown.expect(UnknownFeeCommandException.class); runFlow(); } @Test public void testFeeExtension_invalidCommand_v06() throws Exception { - thrown.expect(UnknownFeeCommandException.class); setEppInput("domain_check_fee_invalid_command_v06.xml"); + thrown.expect(UnknownFeeCommandException.class); runFlow(); } @Test public void testFeeExtension_invalidCommand_v11() throws Exception { - thrown.expect(UnknownFeeCommandException.class); setEppInput("domain_check_fee_invalid_command_v11.xml"); + thrown.expect(UnknownFeeCommandException.class); runFlow(); } @Test public void testFeeExtension_invalidCommand_v12() throws Exception { - thrown.expect(UnknownFeeCommandException.class); setEppInput("domain_check_fee_invalid_command_v12.xml"); + thrown.expect(UnknownFeeCommandException.class); runFlow(); } diff --git a/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java b/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java index 9ba38f6fd..48139b4ce 100644 --- a/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainDeleteFlowTest.java @@ -621,16 +621,15 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCaseof()) .build()); + thrown.expect(NotAuthorizedForTldException.class); runFlow(); } @@ -673,28 +673,28 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCaseof()) .build()); persistDomain(); + thrown.expect(NotAuthorizedForTldException.class); runFlow(); } @@ -605,11 +605,11 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase substitutions) throws Exception { - thrown.expect(CurrencyUnitMismatchException.class); setEppInput("domain_update_restore_request_fee.xml", substitutions); persistPendingDeleteDomain(); persistResource( @@ -393,6 +392,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(); } @@ -413,127 +413,126 @@ public class DomainRestoreRequestFlowTest extends @Test public void testFailure_feeGivenInWrongScale_v06() throws Exception { - thrown.expect(CurrencyValueScaleException.class); setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_06_MAP); persistPendingDeleteDomain(); + thrown.expect(CurrencyValueScaleException.class); runFlow(); } @Test public void testFailure_feeGivenInWrongScale_v11() throws Exception { - thrown.expect(CurrencyValueScaleException.class); setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_11_MAP); persistPendingDeleteDomain(); + thrown.expect(CurrencyValueScaleException.class); runFlow(); } @Test public void testFailure_feeGivenInWrongScale_v12() throws Exception { - thrown.expect(CurrencyValueScaleException.class); setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_12_MAP); persistPendingDeleteDomain(); + thrown.expect(CurrencyValueScaleException.class); runFlow(); } @Test public void testFailure_notInRedemptionPeriod() throws Exception { - thrown.expect(DomainNotEligibleForRestoreException.class); persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder() .setDeletionTime(clock.nowUtc().plusDays(4)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .build()); + thrown.expect(DomainNotEligibleForRestoreException.class); runFlow(); } @Test public void testFailure_notDeleted() throws Exception { - thrown.expect(DomainNotEligibleForRestoreException.class); persistActiveDomain(getUniqueIdFromCommand()); + thrown.expect(DomainNotEligibleForRestoreException.class); runFlow(); } @Test public void testFailure_fullyDeleted() throws Exception { - thrown.expect(ResourceDoesNotExistException.class); persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); + thrown.expect(ResourceDoesNotExistException.class); runFlow(); } @Test public void testFailure_withChange() throws Exception { - thrown.expect(RestoreCommandIncludesChangesException.class); persistPendingDeleteDomain(); setEppInput("domain_update_restore_request_with_change.xml"); + thrown.expect(RestoreCommandIncludesChangesException.class); runFlow(); } @Test public void testFailure_withAdd() throws Exception { - thrown.expect(RestoreCommandIncludesChangesException.class); persistPendingDeleteDomain(); setEppInput("domain_update_restore_request_with_add.xml"); + thrown.expect(RestoreCommandIncludesChangesException.class); runFlow(); } @Test public void testFailure_withRemove() throws Exception { - thrown.expect(RestoreCommandIncludesChangesException.class); persistPendingDeleteDomain(); setEppInput("domain_update_restore_request_with_remove.xml"); + thrown.expect(RestoreCommandIncludesChangesException.class); runFlow(); } @Test public void testFailure_withSecDnsExtension() throws Exception { - thrown.expect(UnimplementedExtensionException.class); persistPendingDeleteDomain(); setEppInput("domain_update_restore_request_with_secdns.xml"); + thrown.expect(UnimplementedExtensionException.class); runFlow(); } @Test public void testFailure_unauthorizedClient() throws Exception { - thrown.expect(ResourceNotOwnedException.class); sessionMetadata.setClientId("NewRegistrar"); persistPendingDeleteDomain(); + thrown.expect(ResourceNotOwnedException.class); runFlow(); } @Test public void testFailure_notAuthorizedForTld() throws Exception { - thrown.expect(NotAuthorizedForTldException.class); persistResource( Registrar.loadByClientId("TheRegistrar") .asBuilder() .setAllowedTlds(ImmutableSet.of()) .build()); persistPendingDeleteDomain(); + thrown.expect(NotAuthorizedForTldException.class); runFlow(); } @Test public void testSuccess_superuserUnauthorizedClient() throws Exception { - thrown.expect(ResourceNotOwnedException.class); sessionMetadata.setClientId("NewRegistrar"); persistPendingDeleteDomain(); + thrown.expect(ResourceNotOwnedException.class); runFlowAssertResponse(readFile("domain_update_response.xml")); } @Test public void testFailure_premiumBlocked() throws Exception { - thrown.expect(PremiumNameBlockedException.class); createTld("example"); setEppInput("domain_update_restore_request_premium.xml"); persistPendingDeleteDomain(); // Modify the Registrar to block premium names. persistResource( Registrar.loadByClientId("TheRegistrar").asBuilder().setBlockPremiumNames(true).build()); + thrown.expect(PremiumNameBlockedException.class); runFlow(); } @Test public void testFailure_reservedBlocked() throws Exception { - thrown.expect(DomainReservedException.class); createTld("tld"); persistResource( Registry.get("tld") @@ -541,15 +540,16 @@ public class DomainRestoreRequestFlowTest extends .setReservedLists(persistReservedList("tld-reserved", "example,FULLY_BLOCKED")) .build()); persistPendingDeleteDomain(); + thrown.expect(DomainReservedException.class); runFlow(); } @Test public void testFailure_feeNotProvidedOnPremiumName() throws Exception { - thrown.expect(FeesRequiredForPremiumNameException.class); createTld("example"); setEppInput("domain_update_restore_request_premium.xml"); persistPendingDeleteDomain(); + thrown.expect(FeesRequiredForPremiumNameException.class); runFlow(); } diff --git a/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java index 77136c5c6..0094b98aa 100644 --- a/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferApproveFlowTest.java @@ -379,106 +379,106 @@ public class DomainTransferApproveFlowTest @Test public void testFailure_badContactPassword() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); // Change the contact's password so it does not match the password in the file. contact = persistResource( contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); + thrown.expect(BadAuthInfoForResourceException.class); doFailingTest("domain_transfer_approve_contact_authinfo.xml"); } @Test public void testFailure_badDomainPassword() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); // Change the domain's password so it does not match the password in the file. domain = persistResource(domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); + thrown.expect(BadAuthInfoForResourceException.class); doFailingTest("domain_transfer_approve_domain_authinfo.xml"); } @Test public void testFailure_neverBeenTransferred() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(null); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_approve.xml"); } @Test public void testFailure_clientApproved() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.CLIENT_APPROVED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_approve.xml"); } @Test public void testFailure_clientRejected() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.CLIENT_REJECTED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_approve.xml"); } @Test public void testFailure_clientCancelled() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.CLIENT_CANCELLED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_approve.xml"); } @Test public void testFailure_serverApproved() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.SERVER_APPROVED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_approve.xml"); } @Test public void testFailure_serverCancelled() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.SERVER_CANCELLED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_approve.xml"); } @Test public void testFailure_gainingClient() throws Exception { - thrown.expect(ResourceNotOwnedException.class); setClientIdForFlow("NewRegistrar"); + thrown.expect(ResourceNotOwnedException.class); doFailingTest("domain_transfer_approve.xml"); } @Test public void testFailure_unrelatedClient() throws Exception { - thrown.expect(ResourceNotOwnedException.class); setClientIdForFlow("ClientZ"); + thrown.expect(ResourceNotOwnedException.class); doFailingTest("domain_transfer_approve.xml"); } @Test public void testFailure_deletedDomain() throws Exception { - thrown.expect(ResourceDoesNotExistException.class, - String.format("(%s)", getUniqueIdFromCommand())); domain = persistResource( domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); + thrown.expect(ResourceDoesNotExistException.class, + String.format("(%s)", getUniqueIdFromCommand())); doFailingTest("domain_transfer_approve.xml"); } @Test public void testFailure_nonexistentDomain() throws Exception { + deleteResource(domain); thrown.expect(ResourceDoesNotExistException.class, String.format("(%s)", getUniqueIdFromCommand())); - deleteResource(domain); doFailingTest("domain_transfer_approve.xml"); } @Test public void testFailure_notAuthorizedForTld() throws Exception { - thrown.expect(NotAuthorizedForTldException.class); persistResource( Registrar.loadByClientId("TheRegistrar") .asBuilder() .setAllowedTlds(ImmutableSet.of()) .build()); + thrown.expect(NotAuthorizedForTldException.class); doSuccessfulTest("tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml"); } diff --git a/javatests/google/registry/flows/domain/DomainTransferCancelFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferCancelFlowTest.java index 148cfed58..3964a00e3 100644 --- a/javatests/google/registry/flows/domain/DomainTransferCancelFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferCancelFlowTest.java @@ -192,108 +192,108 @@ public class DomainTransferCancelFlowTest @Test public void testFailure_badContactPassword() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); // Change the contact's password so it does not match the password in the file. contact = persistResource( contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); + thrown.expect(BadAuthInfoForResourceException.class); doFailingTest("domain_transfer_cancel_contact_authinfo.xml"); } @Test public void testFailure_badDomainPassword() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); // Change the domain's password so it does not match the password in the file. domain = persistResource(domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); + thrown.expect(BadAuthInfoForResourceException.class); doFailingTest("domain_transfer_cancel_domain_authinfo.xml"); } @Test public void testFailure_neverBeenTransferred() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(null); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_cancel.xml"); } @Test public void testFailure_clientApproved() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.CLIENT_APPROVED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_cancel.xml"); } @Test public void testFailure_clientRejected() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.CLIENT_REJECTED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_cancel.xml"); } @Test public void testFailure_clientCancelled() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.CLIENT_CANCELLED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_cancel.xml"); } @Test public void testFailure_serverApproved() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.SERVER_APPROVED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_cancel.xml"); } @Test public void testFailure_serverCancelled() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.SERVER_CANCELLED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_cancel.xml"); } @Test public void testFailure_sponsoringClient() throws Exception { - thrown.expect(NotTransferInitiatorException.class); setClientIdForFlow("TheRegistrar"); + thrown.expect(NotTransferInitiatorException.class); doFailingTest("domain_transfer_cancel.xml"); } @Test public void testFailure_unrelatedClient() throws Exception { - thrown.expect(NotTransferInitiatorException.class); setClientIdForFlow("ClientZ"); + thrown.expect(NotTransferInitiatorException.class); doFailingTest("domain_transfer_cancel.xml"); } @Test public void testFailure_deletedDomain() throws Exception { + domain = persistResource( + domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); thrown.expect( ResourceDoesNotExistException.class, String.format("(%s)", getUniqueIdFromCommand())); - domain = persistResource( - domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); doFailingTest("domain_transfer_cancel.xml"); } @Test public void testFailure_nonexistentDomain() throws Exception { + deleteResource(domain); thrown.expect( ResourceDoesNotExistException.class, String.format("(%s)", getUniqueIdFromCommand())); - deleteResource(domain); doFailingTest("domain_transfer_cancel.xml"); } @Test public void testFailure_notAuthorizedForTld() throws Exception { - thrown.expect(NotAuthorizedForTldException.class); persistResource( Registrar.loadByClientId("NewRegistrar") .asBuilder() .setAllowedTlds(ImmutableSet.of()) .build()); + thrown.expect(NotAuthorizedForTldException.class); doSuccessfulTest("domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml"); } diff --git a/javatests/google/registry/flows/domain/DomainTransferQueryFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferQueryFlowTest.java index b4f676cbf..14c73ae96 100644 --- a/javatests/google/registry/flows/domain/DomainTransferQueryFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferQueryFlowTest.java @@ -170,55 +170,55 @@ public class DomainTransferQueryFlowTest @Test public void testFailure_badContactPassword() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); // Change the contact's password so it does not match the password in the file. contact = persistResource( contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); + thrown.expect(BadAuthInfoForResourceException.class); doFailingTest("domain_transfer_query_contact_authinfo.xml"); } @Test public void testFailure_badDomainPassword() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); // Change the domain's password so it does not match the password in the file. domain = persistResource(domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); + thrown.expect(BadAuthInfoForResourceException.class); doFailingTest("domain_transfer_query_domain_authinfo.xml"); } @Test public void testFailure_neverBeenTransferred() throws Exception { - thrown.expect(NoTransferHistoryToQueryException.class); changeTransferStatus(null); + thrown.expect(NoTransferHistoryToQueryException.class); doFailingTest("domain_transfer_query.xml"); } @Test public void testFailure_unrelatedClient() throws Exception { - thrown.expect(NotAuthorizedToViewTransferException.class); setClientIdForFlow("ClientZ"); + thrown.expect(NotAuthorizedToViewTransferException.class); doFailingTest("domain_transfer_query.xml"); } @Test public void testFailure_deletedDomain() throws Exception { + domain = persistResource( + domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); thrown.expect( ResourceDoesNotExistException.class, String.format("(%s)", getUniqueIdFromCommand())); - domain = persistResource( - domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); doFailingTest("domain_transfer_query.xml"); } @Test public void testFailure_nonexistentDomain() throws Exception { + deleteResource(domain); thrown.expect( ResourceDoesNotExistException.class, String.format("(%s)", getUniqueIdFromCommand())); - deleteResource(domain); doFailingTest("domain_transfer_query.xml"); } } diff --git a/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java index 06d4e89d4..0c9aba8e7 100644 --- a/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferRejectFlowTest.java @@ -153,109 +153,109 @@ public class DomainTransferRejectFlowTest @Test public void testFailure_notAuthorizedForTld() throws Exception { - thrown.expect(NotAuthorizedForTldException.class); persistResource( Registrar.loadByClientId("TheRegistrar") .asBuilder() .setAllowedTlds(ImmutableSet.of()) .build()); + thrown.expect(NotAuthorizedForTldException.class); doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml"); } @Test public void testFailure_badContactPassword() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); // Change the contact's password so it does not match the password in the file. contact = persistResource( contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); + thrown.expect(BadAuthInfoForResourceException.class); doFailingTest("domain_transfer_reject_contact_authinfo.xml"); } @Test public void testFailure_badDomainPassword() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); // Change the domain's password so it does not match the password in the file. domain = persistResource( domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); + thrown.expect(BadAuthInfoForResourceException.class); doFailingTest("domain_transfer_reject_domain_authinfo.xml"); } @Test public void testFailure_neverBeenTransferred() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(null); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_reject.xml"); } @Test public void testFailure_clientApproved() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.CLIENT_APPROVED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_reject.xml"); } @Test public void testFailure_clientRejected() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.CLIENT_REJECTED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_reject.xml"); } @Test public void testFailure_clientCancelled() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.CLIENT_CANCELLED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_reject.xml"); } @Test public void testFailure_serverApproved() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.SERVER_APPROVED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_reject.xml"); } @Test public void testFailure_serverCancelled() throws Exception { - thrown.expect(NotPendingTransferException.class); changeTransferStatus(TransferStatus.SERVER_CANCELLED); + thrown.expect(NotPendingTransferException.class); doFailingTest("domain_transfer_reject.xml"); } @Test public void testFailure_gainingClient() throws Exception { - thrown.expect(ResourceNotOwnedException.class); setClientIdForFlow("NewRegistrar"); + thrown.expect(ResourceNotOwnedException.class); doFailingTest("domain_transfer_reject.xml"); } @Test public void testFailure_unrelatedClient() throws Exception { - thrown.expect(ResourceNotOwnedException.class); setClientIdForFlow("ClientZ"); + thrown.expect(ResourceNotOwnedException.class); doFailingTest("domain_transfer_reject.xml"); } @Test public void testFailure_deletedDomain() throws Exception { + domain = persistResource( + domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); thrown.expect( ResourceDoesNotExistException.class, String.format("(%s)", getUniqueIdFromCommand())); - domain = persistResource( - domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); doFailingTest("domain_transfer_reject.xml"); } @Test public void testFailure_nonexistentDomain() throws Exception { + deleteResource(domain); thrown.expect( ResourceDoesNotExistException.class, String.format("(%s)", getUniqueIdFromCommand())); - deleteResource(domain); doFailingTest("domain_transfer_reject.xml"); } diff --git a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java index bc76a706b..19e6ef63f 100644 --- a/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainTransferRequestFlowTest.java @@ -493,12 +493,12 @@ public class DomainTransferRequestFlowTest @Test public void testFailure_notAuthorizedForTld() throws Exception { - thrown.expect(NotAuthorizedForTldException.class); persistResource( Registrar.loadByClientId("NewRegistrar") .asBuilder() .setAllowedTlds(ImmutableSet.of()) .build()); + thrown.expect(NotAuthorizedForTldException.class); doSuccessfulTest("domain_transfer_request.xml", "domain_transfer_request_response.xml"); } @@ -548,7 +548,6 @@ public class DomainTransferRequestFlowTest } private void runWrongCurrencyTest(Map substitutions) throws Exception { - thrown.expect(CurrencyUnitMismatchException.class); persistResource( Registry.get("tld") .asBuilder() @@ -559,6 +558,7 @@ public class DomainTransferRequestFlowTest .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) .setServerStatusChangeBillingCost(Money.of(EUR, 19)) .build()); + thrown.expect(CurrencyUnitMismatchException.class); doFailingTest("domain_transfer_request_fee.xml", substitutions); } @@ -597,12 +597,12 @@ public class DomainTransferRequestFlowTest private void runWrongFeeAmountTest(Map substitutions) throws Exception { - thrown.expect(FeesMismatchException.class); persistResource( Registry.get("tld") .asBuilder() .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20))) .build()); + thrown.expect(FeesMismatchException.class); doFailingTest("domain_transfer_request_fee.xml", substitutions); } @@ -623,18 +623,18 @@ public class DomainTransferRequestFlowTest @Test public void testFailure_premiumBlocked() throws Exception { - thrown.expect(PremiumNameBlockedException.class); setupDomain("rich", "example"); // Modify the Registrar to block premium names. persistResource( Registrar.loadByClientId("NewRegistrar").asBuilder().setBlockPremiumNames(true).build()); + thrown.expect(PremiumNameBlockedException.class); doFailingTest("domain_transfer_request_premium.xml"); } @Test public void testFailure_feeNotProvidedOnPremiumName() throws Exception { - thrown.expect(FeesRequiredForPremiumNameException.class); setupDomain("rich", "example"); + thrown.expect(FeesRequiredForPremiumNameException.class); doFailingTest("domain_transfer_request_premium.xml"); } @@ -646,21 +646,21 @@ public class DomainTransferRequestFlowTest @Test public void testFailure_badContactPassword() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); // Change the contact's password so it does not match the password in the file. contact = persistResource( contact.asBuilder() .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); + thrown.expect(BadAuthInfoForResourceException.class); doFailingTest("domain_transfer_request.xml"); } @Test public void testFailure_badContactRepoId() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); // 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. contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build(); + thrown.expect(BadAuthInfoForResourceException.class); doFailingTest("domain_transfer_request.xml"); } @@ -696,40 +696,40 @@ public class DomainTransferRequestFlowTest @Test public void testFailure_pending() throws Exception { - thrown.expect(AlreadyPendingTransferException.class); domain = persistResource(domain.asBuilder() .setTransferData(domain.getTransferData().asBuilder() .setTransferStatus(TransferStatus.PENDING) .setPendingTransferExpirationTime(clock.nowUtc().plusDays(1)) .build()) .build()); + thrown.expect(AlreadyPendingTransferException.class); doFailingTest("domain_transfer_request.xml"); } @Test public void testFailure_badDomainPassword() throws Exception { - thrown.expect(BadAuthInfoForResourceException.class); // Change the domain's password so it does not match the password in the file. domain = persistResource(domain.asBuilder() .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .build()); + thrown.expect(BadAuthInfoForResourceException.class); doFailingTest("domain_transfer_request_domain_authinfo.xml"); } @Test public void testFailure_sponsoringClient() throws Exception { - thrown.expect(ObjectAlreadySponsoredException.class); setClientIdForFlow("TheRegistrar"); + thrown.expect(ObjectAlreadySponsoredException.class); doFailingTest("domain_transfer_request.xml"); } @Test public void testFailure_deletedDomain() throws Exception { + domain = persistResource( + domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); thrown.expect( ResourceDoesNotExistException.class, String.format("(%s)", getUniqueIdFromCommand())); - domain = persistResource( - domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); doFailingTest("domain_transfer_request.xml"); } @@ -744,10 +744,10 @@ public class DomainTransferRequestFlowTest @Test public void testFailure_nonexistentDomain() throws Exception { + deleteResource(domain); thrown.expect( ResourceDoesNotExistException.class, String.format("(%s)", getUniqueIdFromCommand())); - deleteResource(domain); doFailingTest("domain_transfer_request.xml"); } @@ -759,9 +759,9 @@ public class DomainTransferRequestFlowTest @Test public void testFailure_pendingDelete() throws Exception { - thrown.expect(ResourceStatusProhibitsOperationException.class); domain = persistResource( domain.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build()); + thrown.expect(ResourceStatusProhibitsOperationException.class); doFailingTest("domain_transfer_request.xml"); } diff --git a/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java b/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java index d6aadbed8..b6d075323 100644 --- a/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainUpdateFlowTest.java @@ -444,10 +444,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase expectedException, String xmlFilename) throws Exception { - thrown.expect(expectedException); setEppInput(xmlFilename); persistReferencedEntities(); persistActiveDomain(getUniqueIdFromCommand()); + thrown.expect(expectedException); runFlow(); } @@ -793,7 +793,6 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase builder = new ImmutableSet.Builder<>(); for (int i = 0; i < 8; ++i) { builder.add(DelegationSignerData.create(i, 2, 3, new byte[]{0, 1, 2})); @@ -804,99 +803,99 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase exception) throws Exception { - thrown.expect(exception); persistResource( newHostResource(getUniqueIdFromCommand()).asBuilder() .setStatusValues(ImmutableSet.of(statusValue)) .build()); + thrown.expect(exception); runFlow(); } @@ -87,10 +87,10 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase { @Test public void testFailure_noSuchMessage() throws Exception { + assertTransactionalFlow(true); thrown.expect( MessageDoesNotExistException.class, String.format("(1-3-EXAMPLE-4-%d)", MESSAGE_ID)); - assertTransactionalFlow(true); runFlow(); } @Test public void testFailure_invalidId_wrongNumberOfComponents() throws Exception { - thrown.expect(InvalidMessageIdException.class); setEppInput("poll_ack_invalid_id.xml"); assertTransactionalFlow(true); + thrown.expect(InvalidMessageIdException.class); runFlow(); } @Test public void testFailure_invalidId_stringInsteadOfNumeric() throws Exception { - thrown.expect(InvalidMessageIdException.class); setEppInput("poll_ack_invalid_string_id.xml"); assertTransactionalFlow(true); + thrown.expect(InvalidMessageIdException.class); runFlow(); } @Test public void testFailure_invalidEppResourceClassId() throws Exception { - thrown.expect(InvalidMessageIdException.class); setEppInput("poll_ack_invalid_eppresource_id.xml"); assertTransactionalFlow(true); + thrown.expect(InvalidMessageIdException.class); runFlow(); } @Test public void testFailure_missingId() throws Exception { - thrown.expect(MissingMessageIdException.class); setEppInput("poll_ack_missing_id.xml"); assertTransactionalFlow(true); + thrown.expect(MissingMessageIdException.class); runFlow(); } @Test public void testFailure_differentRegistrar() throws Exception { - thrown.expect(NotAuthorizedToAckMessageException.class); persistResource( new PollMessage.OneTime.Builder() .setId(MESSAGE_ID) @@ -201,14 +200,12 @@ public class PollAckFlowTest extends FlowTestCase { .setParent(createHistoryEntryForEppResource(domain)) .build()); assertTransactionalFlow(true); + thrown.expect(NotAuthorizedToAckMessageException.class); runFlow(); } @Test public void testFailure_messageInFuture() throws Exception { - thrown.expect( - MessageDoesNotExistException.class, - String.format("(1-3-EXAMPLE-4-%d)", MESSAGE_ID)); persistResource( new PollMessage.OneTime.Builder() .setId(MESSAGE_ID) @@ -218,6 +215,9 @@ public class PollAckFlowTest extends FlowTestCase { .setParent(createHistoryEntryForEppResource(domain)) .build()); assertTransactionalFlow(true); + thrown.expect( + MessageDoesNotExistException.class, + String.format("(1-3-EXAMPLE-4-%d)", MESSAGE_ID)); runFlow(); } } diff --git a/javatests/google/registry/flows/poll/PollRequestFlowTest.java b/javatests/google/registry/flows/poll/PollRequestFlowTest.java index 43fa5f97c..e8f1900cb 100644 --- a/javatests/google/registry/flows/poll/PollRequestFlowTest.java +++ b/javatests/google/registry/flows/poll/PollRequestFlowTest.java @@ -223,9 +223,9 @@ public class PollRequestFlowTest extends FlowTestCase { @Test public void testFailure_messageIdProvided() throws Exception { - thrown.expect(UnexpectedMessageIdException.class); setEppInput("poll_with_id.xml"); assertTransactionalFlow(false); + thrown.expect(UnexpectedMessageIdException.class); runFlow(); } } diff --git a/javatests/google/registry/flows/session/LoginFlowTestCase.java b/javatests/google/registry/flows/session/LoginFlowTestCase.java index 1aeb84014..22faaf2c0 100644 --- a/javatests/google/registry/flows/session/LoginFlowTestCase.java +++ b/javatests/google/registry/flows/session/LoginFlowTestCase.java @@ -66,8 +66,8 @@ public abstract class LoginFlowTestCase extends FlowTestCase { // Also called in subclasses. void doFailingTest(String xmlFilename, Class exception) throws Exception { - thrown.expect(exception); setEppInput(xmlFilename); + thrown.expect(exception); runFlow(); } diff --git a/javatests/google/registry/flows/session/LogoutFlowTest.java b/javatests/google/registry/flows/session/LogoutFlowTest.java index 341355910..0f3a0c2bb 100644 --- a/javatests/google/registry/flows/session/LogoutFlowTest.java +++ b/javatests/google/registry/flows/session/LogoutFlowTest.java @@ -47,8 +47,8 @@ public class LogoutFlowTest extends FlowTestCase { @Test public void testFailure() throws Exception { - thrown.expect(NotLoggedInException.class); sessionMetadata.setClientId(null); // Turn off the implicit login + thrown.expect(NotLoggedInException.class); runFlow(); } } diff --git a/javatests/google/registry/groups/DirectoryGroupsConnectionTest.java b/javatests/google/registry/groups/DirectoryGroupsConnectionTest.java index 3772ea2b0..766bdd4b7 100644 --- a/javatests/google/registry/groups/DirectoryGroupsConnectionTest.java +++ b/javatests/google/registry/groups/DirectoryGroupsConnectionTest.java @@ -136,19 +136,19 @@ public class DirectoryGroupsConnectionTest { @Test public void test_addMemberToGroup_handlesExceptionThrownByDirectoryService() throws Exception { - thrown.expect(GoogleJsonResponseException.class); when(membersInsert.execute()).thenThrow( makeResponseException(SC_INTERNAL_SERVER_ERROR, "Could not contact Directory server.")); + thrown.expect(GoogleJsonResponseException.class); runAddMemberTest(); } @Test public void test_addMemberToGroup_handlesMemberKeyNotFoundException() throws Exception { - thrown.expect(RuntimeException.class, - "Adding member jim@example.com to group spam@example.com " - + "failed because the member wasn't found."); when(membersInsert.execute()).thenThrow( makeResponseException(SC_NOT_FOUND, "Resource Not Found: memberKey")); + thrown.expect(RuntimeException.class, + "Adding member jim@example.com to group spam@example.com " + + "failed because the member wasn't found."); connection.addMemberToGroup("spam@example.com", "jim@example.com", Role.MEMBER); } @@ -196,9 +196,9 @@ public class DirectoryGroupsConnectionTest { @Test public void test_createGroup_handlesExceptionThrownByDirectoryService() throws Exception { - thrown.expect(GoogleJsonResponseException.class); when(groupsInsert.execute()).thenThrow( makeResponseException(SC_INTERNAL_SERVER_ERROR, "Could not contact Directory server.")); + thrown.expect(GoogleJsonResponseException.class); runCreateGroupTest(); } diff --git a/javatests/google/registry/model/billing/RegistrarCreditTest.java b/javatests/google/registry/model/billing/RegistrarCreditTest.java index 3d3829647..f3cc509c3 100644 --- a/javatests/google/registry/model/billing/RegistrarCreditTest.java +++ b/javatests/google/registry/model/billing/RegistrarCreditTest.java @@ -93,8 +93,8 @@ public class RegistrarCreditTest extends EntityTestCase { @Test public void testFailure_CurrencyDoesNotMatchTldCurrency() throws Exception { - thrown.expect(IllegalArgumentException.class, "currency"); assertThat(Registry.get("tld").getCurrency()).isEqualTo(USD); + thrown.expect(IllegalArgumentException.class, "currency"); promoCredit.asBuilder().setTld("tld").setCurrency(JPY).build(); } } diff --git a/javatests/google/registry/model/common/TimedTransitionPropertyTest.java b/javatests/google/registry/model/common/TimedTransitionPropertyTest.java index bc60e6bd4..276fbe746 100644 --- a/javatests/google/registry/model/common/TimedTransitionPropertyTest.java +++ b/javatests/google/registry/model/common/TimedTransitionPropertyTest.java @@ -159,16 +159,15 @@ public class TimedTransitionPropertyTest { @Test public void testFailure_noValuesAfterSimulatedEmptyLoad() throws Exception { - thrown.expect(IllegalStateException.class); timedString = forMapify("0", StringTimedTransition.class); // Simulate a load from datastore by clearing, but don't insert any transitions. timedString.clear(); + thrown.expect(IllegalStateException.class); timedString.checkValidity(); } @Test public void testFailure_noValueAtStartOfTimeAfterSimulatedLoad() throws Exception { - thrown.expect(IllegalStateException.class); // Just for testing, don't extract transitions from a TimedTransitionProperty in real code. StringTimedTransition transition1 = timedString.get(DATE_1); timedString = forMapify("0", StringTimedTransition.class); @@ -176,6 +175,7 @@ public class TimedTransitionPropertyTest { // omit a transition corresponding to START_OF_TIME. timedString.clear(); timedString.put(DATE_1, transition1); + thrown.expect(IllegalStateException.class); timedString.checkValidity(); } } diff --git a/javatests/google/registry/rde/EscrowTaskRunnerTest.java b/javatests/google/registry/rde/EscrowTaskRunnerTest.java index eeb7e6e51..e97e59177 100644 --- a/javatests/google/registry/rde/EscrowTaskRunnerTest.java +++ b/javatests/google/registry/rde/EscrowTaskRunnerTest.java @@ -108,10 +108,10 @@ public class EscrowTaskRunnerTest { @Test public void testRun_lockIsntAvailable_throws503() throws Exception { String lockName = task.getClass().getSimpleName() + " lol"; - thrown.expect(ServiceUnavailableException.class, "Lock in use: " + lockName); clock.setTo(DateTime.parse("2006-06-06T00:30:00Z")); persistResource( Cursor.create(CursorType.RDE_STAGING, DateTime.parse("2006-06-06TZ"), registry)); + thrown.expect(ServiceUnavailableException.class, "Lock in use: " + lockName); Lock.executeWithLocks( new Callable() { @Override diff --git a/javatests/google/registry/rde/GhostrydeTest.java b/javatests/google/registry/rde/GhostrydeTest.java index ee885d02f..6e5534b0d 100644 --- a/javatests/google/registry/rde/GhostrydeTest.java +++ b/javatests/google/registry/rde/GhostrydeTest.java @@ -191,9 +191,9 @@ public class GhostrydeTest { byte[] ciphertext = bsOut.toByteArray(); korruption(ciphertext, ciphertext.length / 2); - thrown.expect(IllegalStateException.class, "tampering"); ByteArrayInputStream bsIn = new ByteArrayInputStream(ciphertext); + thrown.expect(IllegalStateException.class, "tampering"); try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) { ByteStreams.copy(decryptor, ByteStreams.nullOutputStream()); } @@ -219,9 +219,9 @@ public class GhostrydeTest { byte[] ciphertext = bsOut.toByteArray(); korruption(ciphertext, ciphertext.length / 2); - thrown.expect(PGPException.class); ByteArrayInputStream bsIn = new ByteArrayInputStream(ciphertext); + thrown.expect(PGPException.class); try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) { ByteStreams.copy(decryptor, ByteStreams.nullOutputStream()); } @@ -245,10 +245,10 @@ public class GhostrydeTest { output.write(data); } + ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray()); thrown.expect( PGPException.class, "Message was encrypted for keyid a59c132f3589a1d5 but ours is c9598c84ec70b9fd"); - ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray()); try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) { ByteStreams.copy(decryptor, ByteStreams.nullOutputStream()); } diff --git a/javatests/google/registry/rde/RdeImportUtilsTest.java b/javatests/google/registry/rde/RdeImportUtilsTest.java index de20f6a24..f0e24c5d8 100644 --- a/javatests/google/registry/rde/RdeImportUtilsTest.java +++ b/javatests/google/registry/rde/RdeImportUtilsTest.java @@ -152,30 +152,30 @@ public class RdeImportUtilsTest extends ShardableTestCase { /** Verifies thrown error when tld in escrow file is not in the registry */ @Test public void testValidateEscrowFile_tldNotFound() throws Exception { - thrown.expect(IllegalArgumentException.class, "Tld 'badtld' not found in the registry"); xmlInput = DEPOSIT_BADTLD_XML.openBufferedStream(); when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput); + thrown.expect(IllegalArgumentException.class, "Tld 'badtld' not found in the registry"); rdeImportUtils.validateEscrowFileForImport("invalid-deposit-badtld.xml"); } /** Verifies thrown errer when tld in escrow file is not in PREDELEGATION state */ @Test public void testValidateEscrowFile_tldWrongState() throws Exception { + xmlInput = DEPOSIT_GETLD_XML.openBufferedStream(); + when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput); thrown.expect( IllegalArgumentException.class, "Tld 'getld' is in state GENERAL_AVAILABILITY and cannot be imported"); - xmlInput = DEPOSIT_GETLD_XML.openBufferedStream(); - when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput); rdeImportUtils.validateEscrowFileForImport("invalid-deposit-getld.xml"); } /** Verifies thrown error when registrar in escrow file is not in the registry */ @Test public void testValidateEscrowFile_badRegistrar() throws Exception { - thrown.expect( - IllegalArgumentException.class, "Registrar 'RegistrarY' not found in the registry"); xmlInput = DEPOSIT_BADREGISTRAR_XML.openBufferedStream(); when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput); + thrown.expect( + IllegalArgumentException.class, "Registrar 'RegistrarY' not found in the registry"); rdeImportUtils.validateEscrowFileForImport("invalid-deposit-badregistrar.xml"); } diff --git a/javatests/google/registry/storage/drive/DriveConnectionTest.java b/javatests/google/registry/storage/drive/DriveConnectionTest.java index bc7fd8092..1c1ae20cb 100644 --- a/javatests/google/registry/storage/drive/DriveConnectionTest.java +++ b/javatests/google/registry/storage/drive/DriveConnectionTest.java @@ -220,15 +220,15 @@ public class DriveConnectionTest { @Test public void testCreateOrUpdateFile_throwsExceptionWhenMultipleFilesWithNameAlreadyExist() throws Exception { - thrown.expect(IllegalStateException.class, - "Could not update file 'title' in Drive folder id 'driveFolderId' " - + "because multiple files with that name already exist."); ChildList childList = new ChildList() .setItems(ImmutableList.of( new ChildReference().setId("id1"), new ChildReference().setId("id2"))) .setNextPageToken(null); when(childrenList.execute()).thenReturn(childList); + thrown.expect(IllegalStateException.class, + "Could not update file 'title' in Drive folder id 'driveFolderId' " + + "because multiple files with that name already exist."); driveConnection.createOrUpdateFile("title", MediaType.WEBM_VIDEO, "driveFolderId", DATA); } diff --git a/javatests/google/registry/testing/EppExceptionSubject.java b/javatests/google/registry/testing/EppExceptionSubject.java new file mode 100644 index 000000000..b5d9d7632 --- /dev/null +++ b/javatests/google/registry/testing/EppExceptionSubject.java @@ -0,0 +1,69 @@ +// Copyright 2016 The Domain Registry Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package google.registry.testing; + +import static com.google.common.truth.Truth.assertAbout; +import static com.google.common.truth.Truth.assertThat; +import static google.registry.flows.EppXmlTransformer.marshal; +import static google.registry.util.DateTimeUtils.START_OF_TIME; + +import com.google.common.truth.AbstractVerb.DelegatedVerb; +import com.google.common.truth.FailureStrategy; +import com.google.common.truth.Subject; +import com.google.common.truth.SubjectFactory; +import google.registry.flows.EppException; +import google.registry.model.eppcommon.Trid; +import google.registry.model.eppoutput.EppOutput; +import google.registry.model.eppoutput.EppResponse; +import google.registry.testing.TruthChainer.And; +import google.registry.xml.ValidationMode; +import google.registry.xml.XmlException; + +/** Utility methods for asserting things about {@link EppException} instances. */ +public class EppExceptionSubject extends Subject { + + public EppExceptionSubject(FailureStrategy strategy, EppException subject) { + super(strategy, subject); + } + + public And hasMessage(String expected) { + assertThat(actual()).hasMessage(expected); + return new And<>(this); + } + + public And marshalsToXml() { + // Attempt to marshal the exception to EPP. If it doesn't work, this will throw. + try { + marshal( + EppOutput.create(new EppResponse.Builder() + .setTrid(Trid.create(null)) + .setResult(actual().getResult()) + .setExecutionTime(START_OF_TIME) + .build()), + ValidationMode.STRICT); + } catch (XmlException e) { + fail("fails to marshal to XML: " + e.getMessage()); + } + return new And<>(this); + } + + public static DelegatedVerb assertAboutEppExceptions() { + return assertAbout(new SubjectFactory() { + @Override + public EppExceptionSubject getSubject(FailureStrategy strategy, EppException subject) { + return new EppExceptionSubject(strategy, subject); + }}); + } +} diff --git a/javatests/google/registry/testing/ExceptionRule.java b/javatests/google/registry/testing/ExceptionRule.java index 2e6c29af5..3a16f6793 100644 --- a/javatests/google/registry/testing/ExceptionRule.java +++ b/javatests/google/registry/testing/ExceptionRule.java @@ -17,15 +17,9 @@ package google.registry.testing; import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Strings.nullToEmpty; import static com.google.common.base.Throwables.getRootCause; -import static google.registry.flows.EppXmlTransformer.marshal; +import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import google.registry.flows.EppException; -import google.registry.model.eppcommon.Trid; -import google.registry.model.eppoutput.EppOutput; -import google.registry.model.eppoutput.EppResponse; -import google.registry.util.Clock; -import google.registry.util.SystemClock; -import google.registry.xml.ValidationMode; import javax.annotation.Nullable; import org.junit.rules.TestRule; import org.junit.runner.Description; @@ -37,8 +31,6 @@ import org.junit.runners.model.Statement; */ public class ExceptionRule implements TestRule { - private static final Clock CLOCK = new SystemClock(); - @Nullable Class expectedExceptionClass; @@ -68,14 +60,7 @@ public class ExceptionRule implements TestRule { throw e; // We didn't expect this so pass it through. } if (e instanceof EppException) { - // Attempt to marshall the exception to EPP. If it doesn't work, this will throw. - marshal( - EppOutput.create(new EppResponse.Builder() - .setTrid(Trid.create(null)) - .setResult(((EppException) e).getResult()) - .setExecutionTime(CLOCK.nowUtc()) - .build()), - ValidationMode.STRICT); + assertAboutEppExceptions().that((EppException) e).marshalsToXml(); } } }}; diff --git a/javatests/google/registry/tmch/TmchCertificateAuthorityTest.java b/javatests/google/registry/tmch/TmchCertificateAuthorityTest.java index a34803c07..c18b72f35 100644 --- a/javatests/google/registry/tmch/TmchCertificateAuthorityTest.java +++ b/javatests/google/registry/tmch/TmchCertificateAuthorityTest.java @@ -65,27 +65,27 @@ public class TmchCertificateAuthorityTest { @Test public void testFailure_prodRootExpired() throws Exception { - thrown.expectRootCause( - CertificateExpiredException.class, "NotAfter: Sun Jul 23 23:59:59 UTC 2023"); configRule.useTmchProdCert(); clock.setTo(DateTime.parse("2024-01-01T00:00:00Z")); + thrown.expectRootCause( + CertificateExpiredException.class, "NotAfter: Sun Jul 23 23:59:59 UTC 2023"); TmchCertificateAuthority.getRoot(); } @Test public void testFailure_prodRootNotYetValid() throws Exception { - thrown.expectRootCause(CertificateNotYetValidException.class, - "NotBefore: Wed Jul 24 00:00:00 UTC 2013"); configRule.useTmchProdCert(); clock.setTo(DateTime.parse("2000-01-01T00:00:00Z")); + thrown.expectRootCause(CertificateNotYetValidException.class, + "NotBefore: Wed Jul 24 00:00:00 UTC 2013"); TmchCertificateAuthority.getRoot(); } @Test public void testFailure_crlDoesntMatchCerts() throws Exception { - thrown.expectRootCause(SignatureException.class, "Signature does not match"); // Use the prod cl, which won't match our test certificate. TmchCrl.set(readResourceUtf8(TmchCertificateAuthority.class, "icann-tmch.crl")); + thrown.expectRootCause(SignatureException.class, "Signature does not match"); TmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE)); } @@ -96,8 +96,8 @@ public class TmchCertificateAuthorityTest { @Test public void testFailure_verifySignatureDoesntMatch() throws Exception { - thrown.expectRootCause(SignatureException.class, "Signature does not match"); configRule.useTmchProdCert(); + thrown.expectRootCause(SignatureException.class, "Signature does not match"); TmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE)); } diff --git a/javatests/google/registry/tmch/TmchXmlSignatureTest.java b/javatests/google/registry/tmch/TmchXmlSignatureTest.java index a06a22131..4a8f9b6d1 100644 --- a/javatests/google/registry/tmch/TmchXmlSignatureTest.java +++ b/javatests/google/registry/tmch/TmchXmlSignatureTest.java @@ -65,8 +65,8 @@ public class TmchXmlSignatureTest { public void wrongCertificateAuthority() throws Exception { configRule.useTmchProdCert(); - thrown.expectRootCause(SignatureException.class, "Signature does not match"); smdData = loadSmd("active/Court-Agent-Arabic-Active.smd"); + thrown.expectRootCause(SignatureException.class, "Signature does not match"); TmchXmlSignature.verify(smdData); } diff --git a/javatests/google/registry/tools/CreateRegistrarCommandTest.java b/javatests/google/registry/tools/CreateRegistrarCommandTest.java index 32b3cc032..82500f72d 100644 --- a/javatests/google/registry/tools/CreateRegistrarCommandTest.java +++ b/javatests/google/registry/tools/CreateRegistrarCommandTest.java @@ -1145,12 +1145,12 @@ public class CreateRegistrarCommandTest extends CommandTestCase { @Test public void testFailure_bothTldStateFlags() throws Exception { - thrown.expect(IllegalArgumentException.class); DateTime now = DateTime.now(UTC); + thrown.expect(IllegalArgumentException.class); runCommandForced( String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now.plus(1)), "--initial_tld_state=GENERAL_AVAILABILITY", @@ -306,8 +306,8 @@ public class CreateTldCommandTest extends CommandTestCase { @Test public void testFailure_alreadyExists() throws Exception { - thrown.expect(IllegalStateException.class); createTld("xn--q9jyb4c"); + thrown.expect(IllegalStateException.class); runCommandForced("--roid_suffix=NOTDUPE", "xn--q9jyb4c"); } diff --git a/javatests/google/registry/tools/DeletePremiumListCommandTest.java b/javatests/google/registry/tools/DeletePremiumListCommandTest.java index 2da5b498a..574015b42 100644 --- a/javatests/google/registry/tools/DeletePremiumListCommandTest.java +++ b/javatests/google/registry/tools/DeletePremiumListCommandTest.java @@ -15,6 +15,7 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistPremiumList; @@ -55,9 +56,13 @@ public class DeletePremiumListCommandTest extends CommandTestCase(ContactResource(\"3-ROID\"))"); - persistActiveContact("sh8013"); runCommand( "agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw", "agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjMtUk9JRAw"); @@ -159,10 +159,10 @@ public class GetResourceByKeyCommandTest extends CommandTestCase(HostResource(\"3-ROID\"))"); - persistActiveHost("ns1.example.tld"); runCommand( "agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw", "agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjMtUk9JRAw"); diff --git a/javatests/google/registry/tools/GetTldCommandTest.java b/javatests/google/registry/tools/GetTldCommandTest.java index 9671830fb..5eb82f834 100644 --- a/javatests/google/registry/tools/GetTldCommandTest.java +++ b/javatests/google/registry/tools/GetTldCommandTest.java @@ -50,8 +50,8 @@ public class GetTldCommandTest extends CommandTestCase { @Test public void testFailure_oneTldDoesNotExist() throws Exception { - thrown.expect(IllegalArgumentException.class); createTld("xn--q9jyb4c"); + thrown.expect(IllegalArgumentException.class); runCommand("xn--q9jyb4c", "example"); } } diff --git a/javatests/google/registry/tools/MutatingCommandTest.java b/javatests/google/registry/tools/MutatingCommandTest.java index 107506356..9ea05918a 100644 --- a/javatests/google/registry/tools/MutatingCommandTest.java +++ b/javatests/google/registry/tools/MutatingCommandTest.java @@ -15,13 +15,13 @@ package google.registry.tools; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assertWithMessage; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistResource; import static org.joda.time.DateTimeZone.UTC; -import static org.junit.Assert.fail; import google.registry.model.host.HostResource; import google.registry.model.registrar.Registrar; @@ -285,7 +285,7 @@ public class MutatingCommandTest { + "blockPremiumNames -> [false, true]\n"); try { command.execute(); - fail("Expected transaction to fail with IllegalStateException."); + assertWithMessage("Expected transaction to fail with IllegalStateException").fail(); } catch (IllegalStateException e) { assertThat(e.getMessage()).contains("Entity changed since init() was called."); assertThat(ofy().load().entity(host1).now()).isNull(); diff --git a/javatests/google/registry/tools/SetupOteCommandTest.java b/javatests/google/registry/tools/SetupOteCommandTest.java index 89edc7502..ea25571ab 100644 --- a/javatests/google/registry/tools/SetupOteCommandTest.java +++ b/javatests/google/registry/tools/SetupOteCommandTest.java @@ -257,6 +257,7 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_invalidPremiumList() throws Exception { thrown.expect(IllegalArgumentException.class); + runCommandForced( "--ip_whitelist=1.1.1.1", "--registrar=blobio", @@ -266,8 +267,8 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_tldExists() throws Exception { - thrown.expect(IllegalStateException.class); createTld("blobio-sunrise"); + thrown.expect(IllegalStateException.class); runCommandForced( "--ip_whitelist=1.1.1.1", @@ -277,13 +278,12 @@ public class SetupOteCommandTest extends CommandTestCase { @Test public void testFailure_registrarExists() throws Exception { - thrown.expect(IllegalStateException.class); - Registrar registrar = Registrar.loadByClientId("TheRegistrar").asBuilder() .setClientId("blobio-1") .setRegistrarName("blobio-1") .build(); persistResource(registrar); + thrown.expect(IllegalStateException.class); runCommandForced( "--ip_whitelist=1.1.1.1", diff --git a/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java b/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java index 844dbcc18..4a336c4e5 100644 --- a/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java +++ b/javatests/google/registry/tools/UpdateClaimsNoticeCommandTest.java @@ -139,8 +139,8 @@ public class UpdateClaimsNoticeCommandTest extends CommandTestCase { @Test public void testFailure_invalidSmd() throws Exception { - thrown.expectRootCause(ParameterValuePolicyErrorException.class); String smdFile = writeToTmpFile(INVALID_SMD); + thrown.expectRootCause(ParameterValuePolicyErrorException.class); runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile); } @Test public void testFailure_revokedSmd() throws Exception { - thrown.expectRootCause(ParameterValuePolicyErrorException.class); DateTime now = new DateTime(UTC); SignedMarkRevocationList.create(now, ImmutableMap.of(ACTIVE_SMD_ID, now)).save(); String smdFile = writeToTmpFile(ACTIVE_SMD); + thrown.expectRootCause(ParameterValuePolicyErrorException.class); runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile); } @Test public void testFailure_revokedTmv() throws Exception { - thrown.expectRootCause(ParameterValuePolicyErrorException.class); String smdFile = writeToTmpFile(REVOKED_TMV_SMD); + thrown.expectRootCause(ParameterValuePolicyErrorException.class); runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile); } @Test public void testFailure_unparseableXml() throws Exception { - thrown.expectRootCause(ParameterValueSyntaxErrorException.class); String smdFile = writeToTmpFile(base64().encode("This is not XML!".getBytes(UTF_8))); + thrown.expectRootCause(ParameterValueSyntaxErrorException.class); runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile); } @Test public void testFailure_badlyEncodedData() throws Exception { - thrown.expectRootCause(ParameterValueSyntaxErrorException.class); String smdFile = writeToTmpFile("Bad base64 data ~!@#$#@%%$#^$%^&^**&^)(*)(_".getBytes(UTF_8)); + thrown.expectRootCause(ParameterValueSyntaxErrorException.class); runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile); } @Test public void testFailure_wrongLabel() throws Exception { - thrown.expectRootCause(RequiredParameterMissingException.class); String smdFile = writeToTmpFile(DIFFERENT_LABEL_SMD); + thrown.expectRootCause(RequiredParameterMissingException.class); runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile); } @Test public void testFailure_nonExistentApplication() throws Exception { - thrown.expectRootCause(IllegalArgumentException.class); String smdFile = writeToTmpFile(ACTIVE_SMD); + thrown.expectRootCause(IllegalArgumentException.class); runCommand("--id=3-Q9JYB4C", "--smd=" + smdFile); } @Test public void testFailure_deletedApplication() throws Exception { - thrown.expectRootCause(IllegalArgumentException.class); persistResource(domainApplication.asBuilder().setDeletionTime(new DateTime(UTC)).build()); String smdFile = writeToTmpFile(ACTIVE_SMD); + thrown.expectRootCause(IllegalArgumentException.class); runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile); } } diff --git a/javatests/google/registry/tools/UpdateTldCommandTest.java b/javatests/google/registry/tools/UpdateTldCommandTest.java index 13c8a6d06..7706afc47 100644 --- a/javatests/google/registry/tools/UpdateTldCommandTest.java +++ b/javatests/google/registry/tools/UpdateTldCommandTest.java @@ -481,8 +481,6 @@ public class UpdateTldCommandTest extends CommandTestCase { @Test public void testFailure_setCurrentTldState_outOfOrder() throws Exception { - thrown.expect( - IllegalArgumentException.class, "The TLD states are chronologically out of order"); persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setTldStateTransitions( @@ -490,14 +488,13 @@ public class UpdateTldCommandTest extends CommandTestCase { START_OF_TIME, TldState.PREDELEGATION, now.minusMonths(1), TldState.GENERAL_AVAILABILITY)) .build()); + thrown.expect( + IllegalArgumentException.class, "The TLD states are chronologically out of order"); runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"); } @Test public void testFailure_setCurrentTldState_laterTransitionScheduled() throws Exception { - thrown.expect( - IllegalArgumentException.class, - " when there is a later transition already scheduled"); persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setTldStateTransitions( @@ -505,14 +502,14 @@ public class UpdateTldCommandTest extends CommandTestCase { START_OF_TIME, TldState.PREDELEGATION, now.plusMonths(1), TldState.GENERAL_AVAILABILITY)) .build()); + thrown.expect( + IllegalArgumentException.class, + " when there is a later transition already scheduled"); runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"); } @Test public void testFailure_setCurrentTldState_inProduction() throws Exception { - thrown.expect( - IllegalArgumentException.class, - "--set_current_tld_state is not safe to use in production."); persistResource( Registry.get("xn--q9jyb4c").asBuilder() .setTldStateTransitions( @@ -520,6 +517,9 @@ public class UpdateTldCommandTest extends CommandTestCase { START_OF_TIME, TldState.PREDELEGATION, now.minusMonths(1), TldState.GENERAL_AVAILABILITY)) .build()); + thrown.expect( + IllegalArgumentException.class, + "--set_current_tld_state is not safe to use in production."); runCommandInEnvironment( RegistryToolEnvironment.PRODUCTION, "--set_current_tld_state=SUNRISE", diff --git a/javatests/google/registry/tools/UploadClaimsListCommandTest.java b/javatests/google/registry/tools/UploadClaimsListCommandTest.java index c5ce3db4c..ee0558222 100644 --- a/javatests/google/registry/tools/UploadClaimsListCommandTest.java +++ b/javatests/google/registry/tools/UploadClaimsListCommandTest.java @@ -45,101 +45,101 @@ public class UploadClaimsListCommandTest extends CommandTestCase