diff --git a/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java index cfabc19f5..90dff8c97 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationCreateFlowTest.java @@ -33,7 +33,6 @@ 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.testing.JUnitBackports.assertThrows; import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.DateTimeUtils.START_OF_TIME; import static java.util.Comparator.comparing; @@ -45,6 +44,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; import com.googlecode.objectify.Key; +import google.registry.flows.EppException; import google.registry.flows.EppException.UnimplementedExtensionException; import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.domain.DomainApplicationCreateFlow.LandrushApplicationDisallowedDuringSunriseException; @@ -145,9 +145,7 @@ public class DomainApplicationCreateFlowTest private ReservedList createReservedList() { return persistReservedList( - "tld-reserved", - "testandvalidate,FULLY_BLOCKED", - "test---validate,ALLOWED_IN_SUNRISE"); + "tld-reserved", "testandvalidate,FULLY_BLOCKED", "test---validate,ALLOWED_IN_SUNRISE"); } @Before @@ -174,8 +172,7 @@ public class DomainApplicationCreateFlowTest doSuccessfulTest(responseXmlFile, sunriseApplication, 1, null, null); } - private void doSuccessfulTest( - String responseXmlFile, boolean sunriseApplication, int years) + private void doSuccessfulTest(String responseXmlFile, boolean sunriseApplication, int years) throws Exception { doSuccessfulTest(responseXmlFile, sunriseApplication, years, null, null); } @@ -184,7 +181,8 @@ public class DomainApplicationCreateFlowTest String responseXmlFile, boolean sunriseApplication, String feeExtensionVersion, - String feeExtensionNamespace) throws Exception { + String feeExtensionNamespace) + throws Exception { doSuccessfulTest( responseXmlFile, sunriseApplication, 1, feeExtensionVersion, feeExtensionNamespace); } @@ -192,27 +190,35 @@ public class DomainApplicationCreateFlowTest private void doSuccessfulTest( String responseXmlFile, boolean sunriseApplication, - int years, String feeExtensionVersion, - String feeExtensionNamespace) throws Exception { + int years, + String feeExtensionVersion, + String feeExtensionNamespace) + throws Exception { assertTransactionalFlow(true); runFlowAssertResponse( (feeExtensionVersion == null) - ? loadFile(responseXmlFile) - : loadFile( - responseXmlFile, - ImmutableMap.of("FEE_VERSION", feeExtensionVersion, "FEE_NS", feeExtensionNamespace)), + ? loadFile(responseXmlFile) + : loadFile( + responseXmlFile, + ImmutableMap.of( + "FEE_VERSION", feeExtensionVersion, "FEE_NS", feeExtensionNamespace)), "epp.response.extension.creData.applicationID", "epp.response.resData.creData.crDate"); // Check that the domain application was created and persisted with a history entry. // We want the one with the newest creation time, but lacking an index we need this code. List applications = ofy().load().type(DomainApplication.class).list(); applications.sort(comparing(DomainApplication::getCreationTime)); - assertAboutApplications().that(getLast(applications)) - .hasFullyQualifiedDomainName(getUniqueIdFromCommand()).and() - .hasNumEncodedSignedMarks(sunriseApplication ? 1 : 0).and() - .hasPeriodYears(years).and() + assertAboutApplications() + .that(getLast(applications)) + .hasFullyQualifiedDomainName(getUniqueIdFromCommand()) + .and() + .hasNumEncodedSignedMarks(sunriseApplication ? 1 : 0) + .and() + .hasPeriodYears(years) + .and() .hasOnlyOneHistoryEntryWhich() - .hasType(HistoryEntry.Type.DOMAIN_APPLICATION_CREATE).and() + .hasType(HistoryEntry.Type.DOMAIN_APPLICATION_CREATE) + .and() .hasPeriodYears(years); assertNoBillingEvents(); assertThat(loadActiveApplicationsByDomainName(getUniqueIdFromCommand(), clock.nowUtc())) @@ -236,8 +242,10 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_encoded_signed_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - dryRunFlowAssertResponse(loadFile("domain_create_sunrush_encoded_signed_mark_response.xml"), - "epp.response.extension.creData.applicationID", "epp.response.resData.creData.crDate"); + dryRunFlowAssertResponse( + loadFile("domain_create_sunrush_encoded_signed_mark_response.xml"), + "epp.response.extension.creData.applicationID", + "epp.response.resData.creData.crDate"); } @Test @@ -246,7 +254,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_encoded_signed_mark_corrupt.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(SignedMarkParsingErrorException.class, this::runFlow); + EppException thrown = expectThrows(SignedMarkParsingErrorException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -255,7 +264,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_encoded_signed_mark_revoked_cert.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(SignedMarkCertificateRevokedException.class, this::runFlow); + EppException thrown = expectThrows(SignedMarkCertificateRevokedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -266,7 +276,8 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); clock.setTo(DateTime.parse("2022-01-01")); clock.setTo(DateTime.parse("2022-01-01")); - assertThrows(SignedMarkCertificateExpiredException.class, this::runFlow); + EppException thrown = expectThrows(SignedMarkCertificateExpiredException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -276,7 +287,9 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); clock.setTo(DateTime.parse("2012-07-22T00:01:00Z")); - assertThrows(SignedMarkCertificateNotYetValidException.class, this::runFlow); + EppException thrown = + expectThrows(SignedMarkCertificateNotYetValidException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -288,12 +301,15 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); // It's hard to make the real verification code throw a GeneralSecurityException. Instead, // replace the TmchXmlSignature with a stub that throws it for us. - this.testTmchXmlSignature = new TmchXmlSignature(null) { - @Override - public void verify(byte[] smdXml) throws GeneralSecurityException { - throw new GeneralSecurityException(); - }}; - assertThrows(SignedMarkCertificateInvalidException.class, this::runFlow); + this.testTmchXmlSignature = + new TmchXmlSignature(null) { + @Override + public void verify(byte[] smdXml) throws GeneralSecurityException { + throw new GeneralSecurityException(); + } + }; + EppException thrown = expectThrows(SignedMarkCertificateInvalidException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -303,7 +319,9 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_encoded_signed_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(SignedMarkCertificateSignatureException.class, this::runFlow); + EppException thrown = + expectThrows(SignedMarkCertificateSignatureException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -312,7 +330,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_encoded_signed_mark_signature_corrupt.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(SignedMarkSignatureException.class, this::runFlow); + EppException thrown = expectThrows(SignedMarkSignatureException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -321,8 +340,10 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - dryRunFlowAssertResponse(loadFile("domain_create_sunrush_response.xml"), - "epp.response.extension.creData.applicationID", "epp.response.resData.creData.crDate"); + dryRunFlowAssertResponse( + loadFile("domain_create_sunrush_response.xml"), + "epp.response.extension.creData.applicationID", + "epp.response.resData.creData.crDate"); } @Test @@ -333,8 +354,10 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistContactsAndHosts(); clock.advanceOneMilli(); - dryRunFlowAssertResponse(loadFile("domain_create_sunrush_response_claims.xml"), - "epp.response.extension.creData.applicationID", "epp.response.resData.creData.crDate"); + dryRunFlowAssertResponse( + loadFile("domain_create_sunrush_response_claims.xml"), + "epp.response.extension.creData.applicationID", + "epp.response.resData.creData.crDate"); } @Test @@ -344,7 +367,8 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); doSuccessfulTest("domain_create_sunrush_encoded_signed_mark_response.xml", true); - assertAboutApplications().that(getOnlyGlobalResource(DomainApplication.class)) + assertAboutApplications() + .that(getOnlyGlobalResource(DomainApplication.class)) .hasApplicationStatus(ApplicationStatus.VALIDATED); } @@ -355,7 +379,8 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); doSuccessfulTest("domain_create_sunrush_allowedinsunrise_response.xml", true); - assertAboutApplications().that(getOnlyGlobalResource(DomainApplication.class)) + assertAboutApplications() + .that(getOnlyGlobalResource(DomainApplication.class)) .hasApplicationStatus(ApplicationStatus.VALIDATED); } @@ -367,7 +392,8 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); doSuccessfulTest("domain_create_sunrush_encoded_signed_mark_response.xml", true); - assertAboutApplications().that(getOnlyGlobalResource(DomainApplication.class)) + assertAboutApplications() + .that(getOnlyGlobalResource(DomainApplication.class)) .hasApplicationStatus(ApplicationStatus.VALIDATED); } @@ -383,12 +409,16 @@ public class DomainApplicationCreateFlowTest @Test public void testFailure_landrushApplicationReservedAllowedInSunrise() throws Exception { createTld("tld", TldState.SUNRUSH); - persistResource(Registry.get("tld").asBuilder() - .setReservedLists(ImmutableSet.of(createReservedList())).build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setReservedLists(ImmutableSet.of(createReservedList())) + .build()); setEppInput("domain_create_landrush_allowedinsunrise.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(DomainReservedException.class, this::runFlow); + EppException thrown = expectThrows(DomainReservedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -399,7 +429,8 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); // Modify the Registrar to block premium names. persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build()); - assertThrows(PremiumNameBlockedException.class, this::runFlow); + EppException thrown = expectThrows(PremiumNameBlockedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -408,7 +439,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_premium.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(FeesRequiredForPremiumNameException.class, this::runFlow); + EppException thrown = expectThrows(FeesRequiredForPremiumNameException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -420,12 +452,14 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); doSuccessfulTest("domain_create_sunrush_response_claims.xml", false); - assertAboutApplications().that(getOnlyGlobalResource(DomainApplication.class)) - .hasLaunchNotice(LaunchNotice.create( - "370d0b7c9223372036854775807", - "tmch", - DateTime.parse("2010-08-16T09:00:00.0Z"), - DateTime.parse("2009-08-16T09:00:00.0Z"))) + assertAboutApplications() + .that(getOnlyGlobalResource(DomainApplication.class)) + .hasLaunchNotice( + LaunchNotice.create( + "370d0b7c9223372036854775807", + "tmch", + DateTime.parse("2010-08-16T09:00:00.0Z"), + DateTime.parse("2009-08-16T09:00:00.0Z"))) .and() .hasApplicationStatus(ApplicationStatus.VALIDATED); } @@ -437,12 +471,11 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("test-validate", CLAIMS_KEY)); setEppInput("domain_create_sunrush.xml"); persistContactsAndHosts(); - persistResource(Registry.get("tld").asBuilder() - .setClaimsPeriodEnd(clock.nowUtc()) - .build()); + persistResource(Registry.get("tld").asBuilder().setClaimsPeriodEnd(clock.nowUtc()).build()); clock.advanceOneMilli(); doSuccessfulTest("domain_create_sunrush_response.xml", false); - assertAboutApplications().that(getOnlyGlobalResource(DomainApplication.class)) + assertAboutApplications() + .that(getOnlyGlobalResource(DomainApplication.class)) .hasLaunchNotice(null) .and() .hasApplicationStatus(ApplicationStatus.VALIDATED); @@ -517,7 +550,8 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); setEppInput("domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.6")); - assertThrows(UnsupportedFeeAttributeException.class, this::runFlow); + EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -527,7 +561,8 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); setEppInput( "domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.11")); - assertThrows(UnsupportedFeeAttributeException.class, this::runFlow); + EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -537,7 +572,8 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); setEppInput( "domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.12")); - assertThrows(UnsupportedFeeAttributeException.class, this::runFlow); + EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -547,7 +583,8 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); setEppInput( "domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.6")); - assertThrows(UnsupportedFeeAttributeException.class, this::runFlow); + EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -557,7 +594,8 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); setEppInput( "domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.11")); - assertThrows(UnsupportedFeeAttributeException.class, this::runFlow); + EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -567,7 +605,8 @@ public class DomainApplicationCreateFlowTest clock.advanceOneMilli(); setEppInput( "domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.12")); - assertThrows(UnsupportedFeeAttributeException.class, this::runFlow); + EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -576,7 +615,8 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.6")); - assertThrows(UnsupportedFeeAttributeException.class, this::runFlow); + EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -585,7 +625,8 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.11")); - assertThrows(UnsupportedFeeAttributeException.class, this::runFlow); + EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -594,7 +635,8 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.12")); - assertThrows(UnsupportedFeeAttributeException.class, this::runFlow); + EppException thrown = expectThrows(UnsupportedFeeAttributeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -606,12 +648,14 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); doSuccessfulTest("domain_create_landrush_response_claims.xml", false); - assertAboutApplications().that(getOnlyGlobalResource(DomainApplication.class)) - .hasLaunchNotice(LaunchNotice.create( - "370d0b7c9223372036854775807", - "tmch", - DateTime.parse("2010-08-16T09:00:00.0Z"), - DateTime.parse("2009-08-16T09:00:00.0Z"))) + assertAboutApplications() + .that(getOnlyGlobalResource(DomainApplication.class)) + .hasLaunchNotice( + LaunchNotice.create( + "370d0b7c9223372036854775807", + "tmch", + DateTime.parse("2010-08-16T09:00:00.0Z"), + DateTime.parse("2009-08-16T09:00:00.0Z"))) .and() .hasApplicationStatus(ApplicationStatus.VALIDATED); } @@ -623,12 +667,11 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("test-validate", CLAIMS_KEY)); setEppInput("domain_create_landrush.xml"); persistContactsAndHosts(); - persistResource(Registry.get("tld").asBuilder() - .setClaimsPeriodEnd(clock.nowUtc()) - .build()); + persistResource(Registry.get("tld").asBuilder().setClaimsPeriodEnd(clock.nowUtc()).build()); clock.advanceOneMilli(); doSuccessfulTest("domain_create_landrush_response.xml", false); - assertAboutApplications().that(getOnlyGlobalResource(DomainApplication.class)) + assertAboutApplications() + .that(getOnlyGlobalResource(DomainApplication.class)) .hasLaunchNotice(null) .and() .hasApplicationStatus(ApplicationStatus.VALIDATED); @@ -661,7 +704,8 @@ public class DomainApplicationCreateFlowTest @Test public void testSuccess_smdRevokedInFuture() throws Exception { SignedMarkRevocationList.create( - clock.nowUtc(), ImmutableMap.of(SMD_ID, clock.nowUtc().plusDays(1))).save(); + clock.nowUtc(), ImmutableMap.of(SMD_ID, clock.nowUtc().plusDays(1))) + .save(); persistContactsAndHosts(); clock.advanceOneMilli(); doSuccessfulTest("domain_create_sunrise_encoded_signed_mark_response.xml", true); @@ -681,9 +725,10 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); doSuccessfulTest("domain_create_sunrise_encoded_signed_mark_response.xml", true); - assertAboutApplications().that(getOnlyGlobalResource(DomainApplication.class)) - .hasExactlyDsData(DelegationSignerData.create( - 12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC"))); + assertAboutApplications() + .that(getOnlyGlobalResource(DomainApplication.class)) + .hasExactlyDsData( + DelegationSignerData.create(12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC"))); } @Test @@ -700,7 +745,9 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_without_marks.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(LandrushApplicationDisallowedDuringSunriseException.class, this::runFlow); + EppException thrown = + expectThrows(LandrushApplicationDisallowedDuringSunriseException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -715,7 +762,9 @@ public class DomainApplicationCreateFlowTest .setState(State.SUSPENDED) .build()); clock.advanceOneMilli(); - assertThrows(RegistrarMustBeActiveToCreateDomainsException.class, this::runFlow); + EppException thrown = + expectThrows(RegistrarMustBeActiveToCreateDomainsException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -724,7 +773,9 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_signed_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(SunriseApplicationDisallowedDuringLandrushException.class, this::runFlow); + EppException thrown = + expectThrows(SunriseApplicationDisallowedDuringLandrushException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -732,7 +783,8 @@ public class DomainApplicationCreateFlowTest SignedMarkRevocationList.create(clock.nowUtc(), ImmutableMap.of(SMD_ID, clock.nowUtc())).save(); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(SignedMarkRevokedErrorException.class, this::runFlow); + EppException thrown = expectThrows(SignedMarkRevokedErrorException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -741,7 +793,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_14_nameservers.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(TooManyNameserversException.class, this::runFlow); + EppException thrown = expectThrows(TooManyNameserversException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -749,7 +802,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_with_secdns_maxsiglife.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(MaxSigLifeNotSupportedException.class, this::runFlow); + EppException thrown = expectThrows(MaxSigLifeNotSupportedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -757,7 +811,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_signed_mark_with_secdns_9_records.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(TooManyDsRecordsException.class, this::runFlow); + EppException thrown = expectThrows(TooManyDsRecordsException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -765,7 +820,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_wrong_extension.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(UnimplementedExtensionException.class, this::runFlow); + EppException thrown = expectThrows(UnimplementedExtensionException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -773,7 +829,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_signed_mark_reserved.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(DomainReservedException.class, this::runFlow); + EppException thrown = expectThrows(DomainReservedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -812,10 +869,11 @@ public class DomainApplicationCreateFlowTest } private DomainApplication persistSunriseApplication() throws Exception { - return persistResource(newDomainApplication(getUniqueIdFromCommand()) - .asBuilder() - .setPhase(LaunchPhase.SUNRISE) - .build()); + return persistResource( + newDomainApplication(getUniqueIdFromCommand()) + .asBuilder() + .setPhase(LaunchPhase.SUNRISE) + .build()); } @Test @@ -825,7 +883,9 @@ public class DomainApplicationCreateFlowTest persistSunriseApplication(); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(UncontestedSunriseApplicationBlockedInLandrushException.class, this::runFlow); + EppException thrown = + expectThrows(UncontestedSunriseApplicationBlockedInLandrushException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -861,15 +921,18 @@ public class DomainApplicationCreateFlowTest @Test public void testSuccess_landrushLrpApplication() throws Exception { createTld("tld", TldState.LANDRUSH); - persistResource(Registry.get("tld").asBuilder() - .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) - .build()); - LrpTokenEntity token = persistResource( - new LrpTokenEntity.Builder() - .setToken("lrptokentest") - .setAssignee("test-validate.tld") - .setValidTlds(ImmutableSet.of("tld")) + persistResource( + Registry.get("tld") + .asBuilder() + .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) .build()); + LrpTokenEntity token = + persistResource( + new LrpTokenEntity.Builder() + .setToken("lrptokentest") + .setAssignee("test-validate.tld") + .setValidTlds(ImmutableSet.of("tld")) + .build()); setEppInput("domain_create_landrush_lrp.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); @@ -882,15 +945,18 @@ public class DomainApplicationCreateFlowTest // Using an LRP token as superuser should still mark the token as redeemed (i.e. same effect // as non-superuser). createTld("tld", TldState.LANDRUSH); - persistResource(Registry.get("tld").asBuilder() - .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) - .build()); - LrpTokenEntity token = persistResource( - new LrpTokenEntity.Builder() - .setToken("lrptokentest") - .setAssignee("test-validate.tld") - .setValidTlds(ImmutableSet.of("tld")) + persistResource( + Registry.get("tld") + .asBuilder() + .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) .build()); + LrpTokenEntity token = + persistResource( + new LrpTokenEntity.Builder() + .setToken("lrptokentest") + .setAssignee("test-validate.tld") + .setValidTlds(ImmutableSet.of("tld")) + .build()); setEppInput("domain_create_landrush_lrp.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); @@ -901,57 +967,69 @@ public class DomainApplicationCreateFlowTest @Test public void testFailure_landrushLrpApplication_badToken() throws Exception { createTld("tld", TldState.LANDRUSH); - persistResource(Registry.get("tld").asBuilder() - .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) - .build()); - persistResource(new LrpTokenEntity.Builder() - .setToken("lrptokentest2") - .setAssignee("test-validate.tld") - .setValidTlds(ImmutableSet.of("tld")) - .build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) + .build()); + persistResource( + new LrpTokenEntity.Builder() + .setToken("lrptokentest2") + .setAssignee("test-validate.tld") + .setValidTlds(ImmutableSet.of("tld")) + .build()); setEppInput("domain_create_landrush_lrp.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(InvalidLrpTokenException.class, this::runFlow); + EppException thrown = expectThrows(InvalidLrpTokenException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_landrushLrpApplication_tokenForWrongTld() throws Exception { createTld("tld", TldState.LANDRUSH); - persistResource(Registry.get("tld").asBuilder() - .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) - .build()); - persistResource(new LrpTokenEntity.Builder() - .setToken("lrptokentest") - // The below assignee doesn't really make sense here, but as of right now the validation - // in DomainPricingLogic is just a match on the domain name, so this test ensures that - // the registration fails due to invalid TLDs even if everything else otherwise matches. - .setAssignee("test-validate.tld") - .setValidTlds(ImmutableSet.of("other")) - .build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) + .build()); + persistResource( + new LrpTokenEntity.Builder() + .setToken("lrptokentest") + // The below assignee doesn't really make sense here, but as of right now the validation + // in DomainPricingLogic is just a match on the domain name, so this test ensures that + // the registration fails due to invalid TLDs even if everything else otherwise matches. + .setAssignee("test-validate.tld") + .setValidTlds(ImmutableSet.of("other")) + .build()); setEppInput("domain_create_landrush_lrp.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(InvalidLrpTokenException.class, this::runFlow); + EppException thrown = expectThrows(InvalidLrpTokenException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_landrushLrpApplication_usedToken() throws Exception { createTld("tld", TldState.LANDRUSH); - persistResource(Registry.get("tld").asBuilder() - .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) - .build()); - persistResource(new LrpTokenEntity.Builder() - .setToken("lrptokentest") - .setAssignee("test-validate.tld") - .setValidTlds(ImmutableSet.of("tld")) - .setRedemptionHistoryEntry( - Key.create(HistoryEntry.class, "1")) // as long as it's not null - .build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) + .build()); + persistResource( + new LrpTokenEntity.Builder() + .setToken("lrptokentest") + .setAssignee("test-validate.tld") + .setValidTlds(ImmutableSet.of("tld")) + .setRedemptionHistoryEntry( + Key.create(HistoryEntry.class, "1")) // as long as it's not null + .build()); setEppInput("domain_create_landrush_lrp.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(InvalidLrpTokenException.class, this::runFlow); + EppException thrown = expectThrows(InvalidLrpTokenException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -976,18 +1054,21 @@ public class DomainApplicationCreateFlowTest @Test public void testSuccess_landrushApplicationWithLrpToken_noLongerLrp() throws Exception { createTld("tld"); - persistResource(Registry.get("tld").asBuilder() - .setLrpPeriod(new Interval(clock.nowUtc().minusDays(2), clock.nowUtc().minusDays(1))) - .setTldStateTransitions(ImmutableSortedMap.of( - START_OF_TIME, TldState.SUNRISE, - clock.nowUtc(), TldState.LANDRUSH)) - .build()); - LrpTokenEntity token = persistResource( - new LrpTokenEntity.Builder() - .setToken("lrptokentest") - .setAssignee("test-validate.tld") - .setValidTlds(ImmutableSet.of("tld")) + persistResource( + Registry.get("tld") + .asBuilder() + .setLrpPeriod(new Interval(clock.nowUtc().minusDays(2), clock.nowUtc().minusDays(1))) + .setTldStateTransitions( + ImmutableSortedMap.of( + START_OF_TIME, TldState.SUNRISE, clock.nowUtc(), TldState.LANDRUSH)) .build()); + LrpTokenEntity token = + persistResource( + new LrpTokenEntity.Builder() + .setToken("lrptokentest") + .setAssignee("test-validate.tld") + .setValidTlds(ImmutableSet.of("tld")) + .build()); setEppInput("domain_create_landrush_lrp.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); @@ -1000,13 +1081,16 @@ public class DomainApplicationCreateFlowTest @Test public void testFailure_landrush_duringLrpWithMissingToken() throws Exception { createTld("tld", TldState.LANDRUSH); - persistResource(Registry.get("tld").asBuilder() - .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) - .build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) + .build()); setEppInput("domain_create_landrush.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(InvalidLrpTokenException.class, this::runFlow); + EppException thrown = expectThrows(InvalidLrpTokenException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1015,7 +1099,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_months.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(BadPeriodUnitException.class, this::runFlow); + EppException thrown = expectThrows(BadPeriodUnitException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1044,7 +1129,8 @@ public class DomainApplicationCreateFlowTest createTld("foo", TldState.SUNRISE); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(TldDoesNotExistException.class, this::runFlow); + EppException thrown = expectThrows(TldDoesNotExistException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1052,7 +1138,8 @@ public class DomainApplicationCreateFlowTest createTld("tld", TldState.PREDELEGATION); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + EppException thrown = expectThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1060,7 +1147,8 @@ public class DomainApplicationCreateFlowTest persistResource( loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); persistContactsAndHosts(); - assertThrows(NotAuthorizedForTldException.class, this::runFlow); + EppException thrown = expectThrows(NotAuthorizedForTldException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1068,7 +1156,8 @@ public class DomainApplicationCreateFlowTest createTld("tld", TldState.SUNRUSH); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(LaunchPhaseMismatchException.class, this::runFlow); + EppException thrown = expectThrows(LaunchPhaseMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1076,7 +1165,8 @@ public class DomainApplicationCreateFlowTest createTld("tld", TldState.QUIET_PERIOD); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + EppException thrown = expectThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1084,7 +1174,8 @@ public class DomainApplicationCreateFlowTest createTld("tld", TldState.GENERAL_AVAILABILITY); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + EppException thrown = expectThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1092,7 +1183,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_signed_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(LaunchPhaseMismatchException.class, this::runFlow); + EppException thrown = expectThrows(LaunchPhaseMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1149,7 +1241,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_duplicate_contact.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(DuplicateContactForRoleException.class, this::runFlow); + EppException thrown = expectThrows(DuplicateContactForRoleException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1158,7 +1251,8 @@ public class DomainApplicationCreateFlowTest persistContactsAndHosts(); clock.advanceOneMilli(); // We need to test for missing type, but not for invalid - the schema enforces that for us. - assertThrows(MissingContactTypeException.class, this::runFlow); + EppException thrown = expectThrows(MissingContactTypeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1166,7 +1260,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_no_matching_marks.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(NoMarksFoundMatchingDomainException.class, this::runFlow); + EppException thrown = expectThrows(NoMarksFoundMatchingDomainException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1175,7 +1270,8 @@ public class DomainApplicationCreateFlowTest clock.setTo(DateTime.parse("2013-08-09T10:05:59Z").minusSeconds(1)); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(NoMarksFoundMatchingDomainException.class, this::runFlow); + EppException thrown = expectThrows(NoMarksFoundMatchingDomainException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1184,7 +1280,8 @@ public class DomainApplicationCreateFlowTest clock.setTo(DateTime.parse("2017-07-23T22:00:00.000Z")); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(NoMarksFoundMatchingDomainException.class, this::runFlow); + EppException thrown = expectThrows(NoMarksFoundMatchingDomainException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1192,7 +1289,9 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_hex_encoding.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(Base64RequiredForEncodedSignedMarksException.class, this::runFlow); + EppException thrown = + expectThrows(Base64RequiredForEncodedSignedMarksException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1200,7 +1299,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_bad_encoding.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(SignedMarkEncodingErrorException.class, this::runFlow); + EppException thrown = expectThrows(SignedMarkEncodingErrorException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1208,7 +1308,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_bad_encoded_xml.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(SignedMarkParsingErrorException.class, this::runFlow); + EppException thrown = expectThrows(SignedMarkParsingErrorException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1217,7 +1318,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_bad_idn_minna.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(InvalidIdnDomainLabelException.class, this::runFlow); + EppException thrown = expectThrows(InvalidIdnDomainLabelException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1227,7 +1329,8 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY)); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(InvalidTrademarkValidatorException.class, this::runFlow); + EppException thrown = expectThrows(InvalidTrademarkValidatorException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1235,7 +1338,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_signed_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(SignedMarksMustBeEncodedException.class, this::runFlow); + EppException thrown = expectThrows(SignedMarksMustBeEncodedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1243,7 +1347,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_code_with_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(UnsupportedMarkTypeException.class, this::runFlow); + EppException thrown = expectThrows(UnsupportedMarkTypeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1251,7 +1356,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_empty_encoded_signed_mark.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(SignedMarkParsingErrorException.class, this::runFlow); + EppException thrown = expectThrows(SignedMarkParsingErrorException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1260,7 +1366,9 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY)); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(NoticeCannotBeUsedWithSignedMarkException.class, this::runFlow); + EppException thrown = + expectThrows(NoticeCannotBeUsedWithSignedMarkException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1268,7 +1376,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrise_two_signed_marks.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(TooManySignedMarksException.class, this::runFlow); + EppException thrown = expectThrows(TooManySignedMarksException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1278,7 +1387,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(MissingClaimsNoticeException.class, this::runFlow); + EppException thrown = expectThrows(MissingClaimsNoticeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1287,7 +1397,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_claim_notice.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(UnexpectedClaimsNoticeException.class, this::runFlow); + EppException thrown = expectThrows(UnexpectedClaimsNoticeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1296,10 +1407,9 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_claim_notice.xml"); persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistContactsAndHosts(); - persistResource(Registry.get("tld").asBuilder() - .setClaimsPeriodEnd(clock.nowUtc()) - .build()); - assertThrows(ClaimsPeriodEndedException.class, this::runFlow); + persistResource(Registry.get("tld").asBuilder().setClaimsPeriodEnd(clock.nowUtc()).build()); + EppException thrown = expectThrows(ClaimsPeriodEndedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1310,7 +1420,8 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(ExpiredClaimException.class, this::runFlow); + EppException thrown = expectThrows(ExpiredClaimException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1321,7 +1432,8 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(AcceptedTooLongAgoException.class, this::runFlow); + EppException thrown = expectThrows(AcceptedTooLongAgoException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1332,7 +1444,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_malformed_claim_notice1.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(MalformedTcnIdException.class, this::runFlow); + EppException thrown = expectThrows(MalformedTcnIdException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1343,7 +1456,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_sunrush_malformed_claim_notice2.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(MalformedTcnIdException.class, this::runFlow); + EppException thrown = expectThrows(MalformedTcnIdException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1354,7 +1468,8 @@ public class DomainApplicationCreateFlowTest persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(InvalidTcnIdChecksumException.class, this::runFlow); + EppException thrown = expectThrows(InvalidTcnIdChecksumException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1365,7 +1480,8 @@ public class DomainApplicationCreateFlowTest Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(FeesMismatchException.class, this::runFlow); + EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1376,7 +1492,8 @@ public class DomainApplicationCreateFlowTest Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(FeesMismatchException.class, this::runFlow); + EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1387,58 +1504,68 @@ public class DomainApplicationCreateFlowTest Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(FeesMismatchException.class, this::runFlow); + EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_wrongCurrency_v06() throws Exception { createTld("tld", TldState.LANDRUSH); setEppInput("domain_create_landrush_fee.xml", ImmutableMap.of("FEE_VERSION", "0.6")); - persistResource(Registry.get("tld").asBuilder() - .setCurrency(CurrencyUnit.EUR) - .setCreateBillingCost(Money.of(EUR, 13)) - .setRestoreBillingCost(Money.of(EUR, 11)) - .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7))) - .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) - .setServerStatusChangeBillingCost(Money.of(EUR, 19)) - .build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setCurrency(CurrencyUnit.EUR) + .setCreateBillingCost(Money.of(EUR, 13)) + .setRestoreBillingCost(Money.of(EUR, 11)) + .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7))) + .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) + .setServerStatusChangeBillingCost(Money.of(EUR, 19)) + .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(CurrencyUnitMismatchException.class, this::runFlow); + EppException thrown = expectThrows(CurrencyUnitMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_wrongCurrency_v11() throws Exception { createTld("tld", TldState.LANDRUSH); setEppInput("domain_create_landrush_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11")); - persistResource(Registry.get("tld").asBuilder() - .setCurrency(CurrencyUnit.EUR) - .setCreateBillingCost(Money.of(EUR, 13)) - .setRestoreBillingCost(Money.of(EUR, 11)) - .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7))) - .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) - .setServerStatusChangeBillingCost(Money.of(EUR, 19)) - .build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setCurrency(CurrencyUnit.EUR) + .setCreateBillingCost(Money.of(EUR, 13)) + .setRestoreBillingCost(Money.of(EUR, 11)) + .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7))) + .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) + .setServerStatusChangeBillingCost(Money.of(EUR, 19)) + .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(CurrencyUnitMismatchException.class, this::runFlow); + EppException thrown = expectThrows(CurrencyUnitMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_wrongCurrency_v12() throws Exception { createTld("tld", TldState.LANDRUSH); setEppInput("domain_create_landrush_fee.xml", ImmutableMap.of("FEE_VERSION", "0.12")); - persistResource(Registry.get("tld").asBuilder() - .setCurrency(CurrencyUnit.EUR) - .setCreateBillingCost(Money.of(EUR, 13)) - .setRestoreBillingCost(Money.of(EUR, 11)) - .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7))) - .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) - .setServerStatusChangeBillingCost(Money.of(EUR, 19)) - .build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setCurrency(CurrencyUnit.EUR) + .setCreateBillingCost(Money.of(EUR, 13)) + .setRestoreBillingCost(Money.of(EUR, 11)) + .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7))) + .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) + .setServerStatusChangeBillingCost(Money.of(EUR, 19)) + .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(CurrencyUnitMismatchException.class, this::runFlow); + EppException thrown = expectThrows(CurrencyUnitMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1447,7 +1574,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.6")); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(CurrencyValueScaleException.class, this::runFlow); + EppException thrown = expectThrows(CurrencyValueScaleException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1456,7 +1584,8 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.11")); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(CurrencyValueScaleException.class, this::runFlow); + EppException thrown = expectThrows(CurrencyValueScaleException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1465,10 +1594,10 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.12")); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(CurrencyValueScaleException.class, this::runFlow); + EppException thrown = expectThrows(CurrencyValueScaleException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } - @Test public void testFailure_alreadyExists() throws Exception { persistContactsAndHosts(); @@ -1476,13 +1605,18 @@ public class DomainApplicationCreateFlowTest persistActiveDomain(getUniqueIdFromCommand()); try { runFlow(); - assert_().fail( - "Expected to throw ResourceAlreadyExistsException with message " - + "Object with given ID (%s) already exists", - getUniqueIdFromCommand()); + assert_() + .fail( + "Expected to throw ResourceAlreadyExistsException with message " + + "Object with given ID (%s) already exists", + getUniqueIdFromCommand()); } catch (ResourceAlreadyExistsException e) { - assertAboutEppExceptions().that(e).marshalsToXml().and().hasMessage( - String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); + assertAboutEppExceptions() + .that(e) + .marshalsToXml() + .and() + .hasMessage( + String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); } } @@ -1490,9 +1624,11 @@ public class DomainApplicationCreateFlowTest public void testFailure_registrantNotWhitelisted() throws Exception { persistActiveContact("someone"); persistContactsAndHosts(); - persistResource(Registry.get("tld").asBuilder() - .setAllowedRegistrantContactIds(ImmutableSet.of("someone")) - .build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setAllowedRegistrantContactIds(ImmutableSet.of("someone")) + .build()); RegistrantNotAllowedException thrown = expectThrows(RegistrantNotAllowedException.class, this::runFlow); assertThat(thrown).hasMessageThat().contains("jd1234"); @@ -1501,9 +1637,11 @@ public class DomainApplicationCreateFlowTest @Test public void testFailure_nameserverNotWhitelisted() throws Exception { persistContactsAndHosts(); - persistResource(Registry.get("tld").asBuilder() - .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net")) - .build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net")) + .build()); NameserversNotAllowedForTldException thrown = expectThrows(NameserversNotAllowedForTldException.class, this::runFlow); assertThat(thrown).hasMessageThat().contains("ns1.example.net"); @@ -1511,28 +1649,36 @@ public class DomainApplicationCreateFlowTest @Test public void testSuccess_nameserverAndRegistrantWhitelisted() throws Exception { - persistResource(Registry.get("tld").asBuilder() - .setAllowedRegistrantContactIds(ImmutableSet.of("jd1234")) - .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.net", "ns2.example.net")) - .build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setAllowedRegistrantContactIds(ImmutableSet.of("jd1234")) + .setAllowedFullyQualifiedHostNames( + ImmutableSet.of("ns1.example.net", "ns2.example.net")) + .build()); persistContactsAndHosts(); clock.advanceOneMilli(); doSuccessfulTest("domain_create_sunrise_encoded_signed_mark_response.xml", true); - assertAboutApplications().that(getOnlyGlobalResource(DomainApplication.class)) + assertAboutApplications() + .that(getOnlyGlobalResource(DomainApplication.class)) .hasApplicationStatus(ApplicationStatus.VALIDATED); } @Test public void testFailure_emptyNameserverFailsWhitelist() throws Exception { setEppInput("domain_create_sunrise_encoded_signed_mark_no_hosts.xml"); - persistResource(Registry.get("tld").asBuilder() - .setAllowedRegistrantContactIds(ImmutableSet.of("jd1234")) - .setAllowedFullyQualifiedHostNames(ImmutableSet.of("somethingelse.example.net")) - .build()); + persistResource( + Registry.get("tld") + .asBuilder() + .setAllowedRegistrantContactIds(ImmutableSet.of("jd1234")) + .setAllowedFullyQualifiedHostNames(ImmutableSet.of("somethingelse.example.net")) + .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows( - NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, this::runFlow); + EppException thrown = + expectThrows( + NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1584,8 +1730,10 @@ public class DomainApplicationCreateFlowTest .build()); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows( - NameserversNotSpecifiedForNameserverRestrictedDomainException.class, this::runFlow); + EppException thrown = + expectThrows( + NameserversNotSpecifiedForNameserverRestrictedDomainException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -1656,15 +1804,17 @@ public class DomainApplicationCreateFlowTest setEppInput("domain_create_landrush_11_years.xml"); persistContactsAndHosts(); clock.advanceOneMilli(); - assertThrows(ExceedsMaxRegistrationYearsException.class, this::runFlow); + EppException thrown = expectThrows(ExceedsMaxRegistrationYearsException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } - private void doFailingDomainNameTest(String domainName, Class exception) + private void doFailingDomainNameTest(String domainName, Class exception) throws Exception { setEppInput("domain_create_sunrise_signed_mark_uppercase.xml"); eppLoader.replaceAll("TEST-VALIDATE.tld", domainName); persistContactsAndHosts(); - assertThrows(exception, this::runFlow); + EppException thrown = expectThrows(exception, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test diff --git a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java index a438530ce..887020251 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationDeleteFlowTest.java @@ -26,13 +26,14 @@ import static google.registry.testing.DatastoreHelper.newHostResource; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication; import static google.registry.testing.DatastoreHelper.persistResource; -import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.JUnitBackports.expectThrows; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; +import google.registry.flows.EppException; import google.registry.flows.EppException.UnimplementedExtensionException; import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; @@ -77,8 +78,7 @@ public class DomainApplicationDeleteFlowTest @Test public void testDryRun() throws Exception { - persistResource( - newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); dryRunFlowAssertResponse(loadFile("domain_delete_response.xml")); } @@ -88,38 +88,45 @@ public class DomainApplicationDeleteFlowTest persistActiveContact("sh8013"); persistResource(newHostResource("ns1.example.net")); // Create the DomainApplication to test. - persistResource(newDomainApplication("example.tld").asBuilder() - .setRepoId("1-TLD") - .setRegistrant( - Key.create( - loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))) - .setNameservers(ImmutableSet.of( - Key.create( - loadByForeignKey(HostResource.class, "ns1.example.net", clock.nowUtc())))) - .build()); + persistResource( + newDomainApplication("example.tld") + .asBuilder() + .setRepoId("1-TLD") + .setRegistrant( + Key.create(loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))) + .setNameservers( + ImmutableSet.of( + Key.create( + loadByForeignKey(HostResource.class, "ns1.example.net", clock.nowUtc())))) + .build()); doSuccessfulTest(); - for (Key key : ImmutableList.of( - loadAndGetKey(ContactResource.class, "sh8013", clock.nowUtc()), - loadAndGetKey(HostResource.class, "ns1.example.net", clock.nowUtc()))) { + for (Key key : + ImmutableList.of( + loadAndGetKey(ContactResource.class, "sh8013", clock.nowUtc()), + loadAndGetKey(HostResource.class, "ns1.example.net", clock.nowUtc()))) { assertThat(isLinked(key, clock.nowUtc())).isFalse(); } } @Test public void testSuccess_clientDeleteProhibited() throws Exception { - persistResource(newDomainApplication("example.tld").asBuilder() - .setRepoId("1-TLD") - .addStatusValue(StatusValue.CLIENT_DELETE_PROHIBITED) - .build()); + persistResource( + newDomainApplication("example.tld") + .asBuilder() + .setRepoId("1-TLD") + .addStatusValue(StatusValue.CLIENT_DELETE_PROHIBITED) + .build()); doSuccessfulTest(); } @Test public void testSuccess_serverDeleteProhibited() throws Exception { - persistResource(newDomainApplication("example.tld").asBuilder() - .setRepoId("1-TLD") - .addStatusValue(StatusValue.SERVER_DELETE_PROHIBITED) - .build()); + persistResource( + newDomainApplication("example.tld") + .asBuilder() + .setRepoId("1-TLD") + .addStatusValue(StatusValue.SERVER_DELETE_PROHIBITED) + .build()); doSuccessfulTest(); } @@ -132,10 +139,12 @@ public class DomainApplicationDeleteFlowTest @Test public void testFailure_existedButWasDeleted() throws Exception { - persistResource(newDomainApplication("example.tld").asBuilder() - .setRepoId("1-TLD") - .setDeletionTime(clock.nowUtc().minusSeconds(1)) - .build()); + persistResource( + newDomainApplication("example.tld") + .asBuilder() + .setRepoId("1-TLD") + .setDeletionTime(clock.nowUtc().minusSeconds(1)) + .build()); ResourceDoesNotExistException thrown = expectThrows(ResourceDoesNotExistException.class, this::runFlow); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); @@ -144,16 +153,15 @@ public class DomainApplicationDeleteFlowTest @Test public void testFailure_unauthorizedClient() throws Exception { sessionMetadata.setClientId("NewRegistrar"); - persistResource( - newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); - assertThrows(ResourceNotOwnedException.class, this::runFlow); + persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testSuccess_superuserUnauthorizedClient() throws Exception { sessionMetadata.setClientId("NewRegistrar"); - persistResource( - newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); clock.advanceOneMilli(); runFlowAssertResponse( CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml")); @@ -164,9 +172,10 @@ public class DomainApplicationDeleteFlowTest persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); persistResource( loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); - assertThrows(NotAuthorizedForTldException.class, this::runFlow); + EppException thrown = expectThrows(NotAuthorizedForTldException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } - + @Test public void testSuccess_superuserNotAuthorizedForTld() throws Exception { persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); @@ -181,23 +190,27 @@ public class DomainApplicationDeleteFlowTest public void testFailure_sunriseDuringLandrush() throws Exception { createTld("tld", TldState.LANDRUSH); setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld")); - persistResource(newDomainApplication("example.tld") - .asBuilder() - .setRepoId("1-TLD") - .setPhase(LaunchPhase.SUNRISE) - .build()); - assertThrows(SunriseApplicationCannotBeDeletedInLandrushException.class, this::runFlow); + persistResource( + newDomainApplication("example.tld") + .asBuilder() + .setRepoId("1-TLD") + .setPhase(LaunchPhase.SUNRISE) + .build()); + EppException thrown = + expectThrows(SunriseApplicationCannotBeDeletedInLandrushException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testSuccess_superuserSunriseDuringLandrush() throws Exception { createTld("tld", TldState.LANDRUSH); setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld")); - persistResource(newDomainApplication("example.tld") - .asBuilder() - .setRepoId("1-TLD") - .setPhase(LaunchPhase.SUNRISE) - .build()); + persistResource( + newDomainApplication("example.tld") + .asBuilder() + .setRepoId("1-TLD") + .setPhase(LaunchPhase.SUNRISE) + .build()); clock.advanceOneMilli(); runFlowAssertResponse( CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml")); @@ -207,11 +220,12 @@ public class DomainApplicationDeleteFlowTest public void testSuccess_sunrushDuringLandrush() throws Exception { createTld("tld", TldState.LANDRUSH); setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld")); - persistResource(newDomainApplication("example.tld") - .asBuilder() - .setRepoId("1-TLD") - .setPhase(LaunchPhase.SUNRUSH) - .build()); + persistResource( + newDomainApplication("example.tld") + .asBuilder() + .setRepoId("1-TLD") + .setPhase(LaunchPhase.SUNRUSH) + .build()); doSuccessfulTest(); } @@ -219,58 +233,59 @@ public class DomainApplicationDeleteFlowTest public void testSuccess_sunriseDuringSunrush() throws Exception { createTld("tld", TldState.SUNRUSH); setEppInput("domain_delete_application_sunrush.xml"); - persistResource(newDomainApplication("example.tld") - .asBuilder() - .setRepoId("1-TLD") - .setPhase(LaunchPhase.SUNRISE) - .build()); + persistResource( + newDomainApplication("example.tld") + .asBuilder() + .setRepoId("1-TLD") + .setPhase(LaunchPhase.SUNRISE) + .build()); doSuccessfulTest(); } @Test public void testFailure_mismatchedPhase() throws Exception { setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld")); - persistResource( - newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); - assertThrows(LaunchPhaseMismatchException.class, this::runFlow); + persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + EppException thrown = expectThrows(LaunchPhaseMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_wrongExtension() throws Exception { setEppInput("domain_delete_application_wrong_extension.xml"); persistActiveDomainApplication("example.tld"); - assertThrows(UnimplementedExtensionException.class, this::runFlow); + EppException thrown = expectThrows(UnimplementedExtensionException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_predelegation() throws Exception { createTld("tld", TldState.PREDELEGATION); - persistResource( - newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); - assertThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + EppException thrown = expectThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_quietPeriod() throws Exception { createTld("tld", TldState.QUIET_PERIOD); - persistResource( - newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); - assertThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + EppException thrown = expectThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_generalAvailability() throws Exception { createTld("tld", TldState.GENERAL_AVAILABILITY); - persistResource( - newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); - assertThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + EppException thrown = expectThrows(BadCommandForRegistryPhaseException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testSuccess_superuserQuietPeriod() throws Exception { createTld("tld", TldState.QUIET_PERIOD); - persistResource( - newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); clock.advanceOneMilli(); runFlowAssertResponse( CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml")); @@ -279,8 +294,7 @@ public class DomainApplicationDeleteFlowTest @Test public void testSuccess_superuserPredelegation() throws Exception { createTld("tld", TldState.PREDELEGATION); - persistResource( - newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); clock.advanceOneMilli(); runFlowAssertResponse( CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml")); @@ -289,8 +303,7 @@ public class DomainApplicationDeleteFlowTest @Test public void testSuccess_superuserGeneralAvailability() throws Exception { createTld("tld", TldState.GENERAL_AVAILABILITY); - persistResource( - newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); clock.advanceOneMilli(); runFlowAssertResponse( CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_delete_response.xml")); @@ -298,15 +311,14 @@ public class DomainApplicationDeleteFlowTest @Test public void testFailure_applicationIdForDifferentDomain() throws Exception { - persistResource( - newDomainApplication("invalid.tld").asBuilder().setRepoId("1-TLD").build()); - assertThrows(ApplicationDomainNameMismatchException.class, this::runFlow); + persistResource(newDomainApplication("invalid.tld").asBuilder().setRepoId("1-TLD").build()); + EppException thrown = expectThrows(ApplicationDomainNameMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testIcannActivityReportField_getsLogged() throws Exception { - persistResource( - newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); + persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); clock.advanceOneMilli(); runFlow(); assertIcannReportingActivityFieldLogged("srs-dom-delete"); diff --git a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java index 0d964d3d0..bb5c2d9f8 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationInfoFlowTest.java @@ -22,7 +22,7 @@ import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistResource; -import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.JUnitBackports.expectThrows; import com.google.common.base.Predicates; @@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; +import google.registry.flows.EppException; import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException; @@ -67,8 +68,15 @@ public class DomainApplicationInfoFlowTest private HostResource host2; private DomainApplication application; - private enum MarksState { MARKS_EXIST, NO_MARKS_EXIST } - private enum HostsState { HOSTS_EXIST, NO_HOSTS_EXIST } + private enum MarksState { + MARKS_EXIST, + NO_MARKS_EXIST + } + + private enum HostsState { + HOSTS_EXIST, + NO_HOSTS_EXIST + } @Before public void resetClientId() { @@ -82,33 +90,42 @@ public class DomainApplicationInfoFlowTest contact = persistActiveContact("sh8013"); host1 = persistActiveHost("ns1.example.net"); host2 = persistActiveHost("ns1.example.tld"); - application = persistResource(new DomainApplication.Builder() - .setRepoId("123-TLD") - .setFullyQualifiedDomainName("example.tld") - .setPhase(LaunchPhase.SUNRUSH) - .setPersistedCurrentSponsorClientId("NewRegistrar") - .setCreationClientId("TheRegistrar") - .setLastEppUpdateClientId("NewRegistrar") - .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) - .setLastEppUpdateTime(DateTime.parse("1999-12-03T09:00:00.0Z")) - .setRegistrant(Key.create(registrant)) - .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, Key.create(contact)), - DesignatedContact.create(Type.TECH, Key.create(contact)))) - .setNameservers(hostsState.equals(HostsState.HOSTS_EXIST) ? ImmutableSet.of( - Key.create(host1), Key.create(host2)) : null) - .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("2fooBAR"))) - .addStatusValue(StatusValue.PENDING_CREATE) - .setApplicationStatus(ApplicationStatus.PENDING_VALIDATION) - .setEncodedSignedMarks(marksState.equals(MarksState.MARKS_EXIST) - // If we need to include an encoded signed mark, pull it out of the create xml. - ? ImmutableList.of((EncodedSignedMark) - new EppLoader(this, "domain_create_sunrise_encoded_signed_mark.xml") - .getEpp() - .getSingleExtension(LaunchCreateExtension.class) - .getSignedMarks().get(0)) - : null) - .build()); + application = + persistResource( + new DomainApplication.Builder() + .setRepoId("123-TLD") + .setFullyQualifiedDomainName("example.tld") + .setPhase(LaunchPhase.SUNRUSH) + .setPersistedCurrentSponsorClientId("NewRegistrar") + .setCreationClientId("TheRegistrar") + .setLastEppUpdateClientId("NewRegistrar") + .setCreationTimeForTest(DateTime.parse("1999-04-03T22:00:00.0Z")) + .setLastEppUpdateTime(DateTime.parse("1999-12-03T09:00:00.0Z")) + .setRegistrant(Key.create(registrant)) + .setContacts( + ImmutableSet.of( + DesignatedContact.create(Type.ADMIN, Key.create(contact)), + DesignatedContact.create(Type.TECH, Key.create(contact)))) + .setNameservers( + hostsState.equals(HostsState.HOSTS_EXIST) + ? ImmutableSet.of(Key.create(host1), Key.create(host2)) + : null) + .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("2fooBAR"))) + .addStatusValue(StatusValue.PENDING_CREATE) + .setApplicationStatus(ApplicationStatus.PENDING_VALIDATION) + .setEncodedSignedMarks( + marksState.equals(MarksState.MARKS_EXIST) + // If we need to include an encoded signed mark, pull it out of the create + // xml. + ? ImmutableList.of( + (EncodedSignedMark) + new EppLoader(this, "domain_create_sunrise_encoded_signed_mark.xml") + .getEpp() + .getSingleExtension(LaunchCreateExtension.class) + .getSignedMarks() + .get(0)) + : null) + .build()); } private void doSuccessfulTest(String expectedXmlFilename, HostsState hostsState) @@ -241,12 +258,15 @@ public class DomainApplicationInfoFlowTest public void testSuccess_secDns() throws Exception { persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); // Add the dsData to the saved resource and change the nameservers to match the sample xml. - persistResource(application.asBuilder() - .setDsData(ImmutableSet.of(DelegationSignerData.create( - 12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC")))) - .setNameservers(ImmutableSet.of( - Key.create(host1), Key.create(host2))) - .build()); + persistResource( + application + .asBuilder() + .setDsData( + ImmutableSet.of( + DelegationSignerData.create( + 12345, 3, 1, base16().decode("49FD46E6C4B45C55D4AC")))) + .setNameservers(ImmutableSet.of(Key.create(host1), Key.create(host2))) + .build()); doSuccessfulTest("domain_info_sunrise_response_dsdata.xml", HostsState.NO_HOSTS_EXIST); } @@ -254,10 +274,12 @@ public class DomainApplicationInfoFlowTest public void testSuccess_allocated() throws Exception { persistTestEntities(HostsState.HOSTS_EXIST, MarksState.NO_MARKS_EXIST); // Update the application status of the saved resource. - persistResource(application.asBuilder() - .removeStatusValue(StatusValue.PENDING_CREATE) - .setApplicationStatus(ApplicationStatus.ALLOCATED) - .build()); + persistResource( + application + .asBuilder() + .removeStatusValue(StatusValue.PENDING_CREATE) + .setApplicationStatus(ApplicationStatus.ALLOCATED) + .build()); doSuccessfulTest("domain_info_sunrise_allocated.xml", HostsState.HOSTS_EXIST); } @@ -270,12 +292,13 @@ public class DomainApplicationInfoFlowTest @Test public void testFailure_existedButWasDeleted() throws Exception { - persistResource(new DomainApplication.Builder() - .setRepoId("123-COM") - .setFullyQualifiedDomainName("timber.com") - .setDeletionTime(clock.nowUtc().minusDays(1)) - .setRegistrant(Key.create(persistActiveContact("jd1234"))) - .build()); + persistResource( + new DomainApplication.Builder() + .setRepoId("123-COM") + .setFullyQualifiedDomainName("timber.com") + .setDeletionTime(clock.nowUtc().minusDays(1)) + .setRegistrant(Key.create(persistActiveContact("jd1234"))) + .build()); ResourceDoesNotExistException thrown = expectThrows(ResourceDoesNotExistException.class, this::runFlow); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); @@ -283,37 +306,41 @@ public class DomainApplicationInfoFlowTest @Test public void testFailure_unauthorized() throws Exception { - persistResource( - AppEngineRule.makeRegistrar1().asBuilder().setClientId("ClientZ").build()); + persistResource(AppEngineRule.makeRegistrar1().asBuilder().setClientId("ClientZ").build()); sessionMetadata.setClientId("ClientZ"); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); - assertThrows(ResourceNotOwnedException.class, this::runFlow); + EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_applicationIdForDifferentDomain() throws Exception { - persistResource(new DomainApplication.Builder() - .setRepoId("123-TLD") - .setFullyQualifiedDomainName("invalid.tld") - .setRegistrant(Key.create(persistActiveContact("jd1234"))) - .setPhase(LaunchPhase.SUNRUSH) - .build()); - assertThrows(ApplicationDomainNameMismatchException.class, this::runFlow); + persistResource( + new DomainApplication.Builder() + .setRepoId("123-TLD") + .setFullyQualifiedDomainName("invalid.tld") + .setRegistrant(Key.create(persistActiveContact("jd1234"))) + .setPhase(LaunchPhase.SUNRUSH) + .build()); + EppException thrown = expectThrows(ApplicationDomainNameMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_noApplicationId() throws Exception { setEppInput("domain_info_sunrise_no_application_id.xml"); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); - assertThrows(MissingApplicationIdException.class, this::runFlow); + EppException thrown = expectThrows(MissingApplicationIdException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_mismatchedLaunchPhase() throws Exception { persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); - application = persistResource( - application.asBuilder().setPhase(LaunchPhase.SUNRISE).build()); - assertThrows(ApplicationLaunchPhaseMismatchException.class, this::runFlow); + application = persistResource(application.asBuilder().setPhase(LaunchPhase.SUNRISE).build()); + EppException thrown = + expectThrows(ApplicationLaunchPhaseMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } /** Test that we load contacts and hosts as a batch rather than individually. */ diff --git a/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java b/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java index 3244de097..09277ca27 100644 --- a/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainApplicationUpdateFlowTest.java @@ -28,13 +28,14 @@ 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.JUnitBackports.assertThrows; +import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.util.DateTimeUtils.START_OF_TIME; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.googlecode.objectify.Key; +import google.registry.flows.EppException; import google.registry.flows.EppException.UnimplementedExtensionException; import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowUtils.AddRemoveSameValueException; @@ -83,7 +84,7 @@ public class DomainApplicationUpdateFlowTest extends ResourceFlowTestCase { private static final DelegationSignerData SOME_DSDATA = - DelegationSignerData.create(1, 2, 3, new byte[]{0, 1, 2}); + DelegationSignerData.create(1, 2, 3, new byte[] {0, 1, 2}); ContactResource sh8013Contact; ContactResource mak21Contact; @@ -111,13 +112,17 @@ public class DomainApplicationUpdateFlowTest } private DomainApplication persistApplication() throws Exception { - return persistResource(newApplicationBuilder() - .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)), - DesignatedContact.create(Type.ADMIN, Key.create(unusedContact)))) - .setNameservers(ImmutableSet.of(Key.create( - loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())))) - .build()); + return persistResource( + newApplicationBuilder() + .setContacts( + ImmutableSet.of( + DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)), + DesignatedContact.create(Type.ADMIN, Key.create(unusedContact)))) + .setNameservers( + ImmutableSet.of( + Key.create( + loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())))) + .build()); } private Builder newApplicationBuilder() throws Exception { @@ -134,8 +139,10 @@ public class DomainApplicationUpdateFlowTest runFlowAssertResponse(loadFile("domain_update_response.xml")); // Check that the application was updated. These values came from the xml. DomainApplication application = reloadDomainApplication(); - assertAboutApplications().that(application) - .hasStatusValue(StatusValue.CLIENT_HOLD).and() + assertAboutApplications() + .that(application) + .hasStatusValue(StatusValue.CLIENT_HOLD) + .and() .hasOnlyOneHistoryEntryWhich() .hasType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE); assertThat(application.getAuthInfo().getPw().getValue()).isEqualTo("2BARfoo"); @@ -178,8 +185,7 @@ public class DomainApplicationUpdateFlowTest setEppInput("domain_update_sunrise_registrant_to_tech.xml"); persistReferencedEntities(); ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()); - persistResource( - newApplicationBuilder().setRegistrant(Key.create(sh8013)).build()); + persistResource(newApplicationBuilder().setRegistrant(Key.create(sh8013)).build()); clock.advanceOneMilli(); runFlowAssertResponse(loadFile("domain_update_response.xml")); } @@ -190,13 +196,15 @@ public class DomainApplicationUpdateFlowTest persistReferencedEntities(); ContactResource sh8013 = loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()); Key sh8013Key = Key.create(sh8013); - persistResource(newApplicationBuilder() - .setRegistrant(sh8013Key) - .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, sh8013Key), - DesignatedContact.create(Type.BILLING, sh8013Key), - DesignatedContact.create(Type.TECH, sh8013Key))) - .build()); + persistResource( + newApplicationBuilder() + .setRegistrant(sh8013Key) + .setContacts( + ImmutableSet.of( + DesignatedContact.create(Type.ADMIN, sh8013Key), + DesignatedContact.create(Type.BILLING, sh8013Key), + DesignatedContact.create(Type.TECH, sh8013Key))) + .build()); clock.advanceOneMilli(); runFlowAssertResponse(loadFile("domain_update_response.xml")); } @@ -204,11 +212,15 @@ public class DomainApplicationUpdateFlowTest @Test public void testSuccess_removeClientUpdateProhibited() throws Exception { persistReferencedEntities(); - persistResource(persistApplication().asBuilder().setStatusValues( - ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)).build()); + persistResource( + persistApplication() + .asBuilder() + .setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)) + .build()); clock.advanceOneMilli(); runFlow(); - assertAboutApplications().that(reloadDomainApplication()) + assertAboutApplications() + .that(reloadDomainApplication()) .doesNotHaveStatusValue(StatusValue.CLIENT_UPDATE_PROHIBITED); } @@ -222,8 +234,10 @@ public class DomainApplicationUpdateFlowTest assertTransactionalFlow(true); clock.advanceOneMilli(); runFlowAssertResponse(loadFile("domain_update_response.xml")); - assertAboutApplications().that(reloadDomainApplication()) - .hasExactlyDsData(expectedDsData).and() + assertAboutApplications() + .that(reloadDomainApplication()) + .hasExactlyDsData(expectedDsData) + .and() .hasOnlyOneHistoryEntryWhich() .hasType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE); } @@ -233,25 +247,25 @@ public class DomainApplicationUpdateFlowTest doSecDnsSuccessfulTest( "domain_update_sunrise_dsdata_add.xml", null, - ImmutableSet.of(DelegationSignerData.create( - 12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))); + ImmutableSet.of( + DelegationSignerData.create(12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))); } - @Test public void testSuccess_secDnsAddPreservesExisting() throws Exception { doSecDnsSuccessfulTest( "domain_update_sunrise_dsdata_add.xml", ImmutableSet.of(SOME_DSDATA), - ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( - 12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))); + ImmutableSet.of( + SOME_DSDATA, + DelegationSignerData.create(12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))); } @Test public void testSuccess_secDnsAddToMaxRecords() throws Exception { ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); for (int i = 0; i < 7; ++i) { - builder.add(DelegationSignerData.create(i, 2, 3, new byte[]{0, 1, 2})); + builder.add(DelegationSignerData.create(i, 2, 3, new byte[] {0, 1, 2})); } ImmutableSet commonDsData = builder.build(); @@ -259,16 +273,20 @@ public class DomainApplicationUpdateFlowTest "domain_update_sunrise_dsdata_add.xml", commonDsData, ImmutableSet.copyOf( - union(commonDsData, ImmutableSet.of(DelegationSignerData.create( - 12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))))); + union( + commonDsData, + ImmutableSet.of( + DelegationSignerData.create( + 12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))))); } @Test public void testSuccess_secDnsRemove() throws Exception { doSecDnsSuccessfulTest( "domain_update_sunrise_dsdata_rem.xml", - ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( - 12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))), + ImmutableSet.of( + SOME_DSDATA, + DelegationSignerData.create(12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))), ImmutableSet.of(SOME_DSDATA)); } @@ -277,8 +295,9 @@ public class DomainApplicationUpdateFlowTest // As an aside, this test also validates that it's ok to set the 'urgent' attribute to false. doSecDnsSuccessfulTest( "domain_update_sunrise_dsdata_rem_all.xml", - ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( - 12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))), + ImmutableSet.of( + SOME_DSDATA, + DelegationSignerData.create(12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B"))), ImmutableSet.of()); } @@ -286,28 +305,36 @@ public class DomainApplicationUpdateFlowTest public void testSuccess_secDnsAddRemove() throws Exception { doSecDnsSuccessfulTest( "domain_update_sunrise_dsdata_add_rem.xml", - ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( - 12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))), - ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( - 12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))); + ImmutableSet.of( + SOME_DSDATA, + DelegationSignerData.create(12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))), + ImmutableSet.of( + SOME_DSDATA, + DelegationSignerData.create(12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))); } @Test public void testSuccess_secDnsAddRemoveToMaxRecords() throws Exception { ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); for (int i = 0; i < 7; ++i) { - builder.add(DelegationSignerData.create(i, 2, 3, new byte[]{0, 1, 2})); + builder.add(DelegationSignerData.create(i, 2, 3, new byte[] {0, 1, 2})); } ImmutableSet commonDsData = builder.build(); doSecDnsSuccessfulTest( "domain_update_sunrise_dsdata_add_rem.xml", ImmutableSet.copyOf( - union(commonDsData, ImmutableSet.of(DelegationSignerData.create( - 12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))))), + union( + commonDsData, + ImmutableSet.of( + DelegationSignerData.create( + 12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))))), ImmutableSet.copyOf( - union(commonDsData, ImmutableSet.of(DelegationSignerData.create( - 12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))))); + union( + commonDsData, + ImmutableSet.of( + DelegationSignerData.create( + 12346, 3, 1, base16().decode("38EC35D5B3A34B44C39B")))))); } @Test @@ -315,10 +342,12 @@ public class DomainApplicationUpdateFlowTest // Adding and removing the same dsData is a no-op because removes are processed first. doSecDnsSuccessfulTest( "domain_update_sunrise_dsdata_add_rem_same.xml", - ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( - 12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))), - ImmutableSet.of(SOME_DSDATA, DelegationSignerData.create( - 12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B")))); + ImmutableSet.of( + SOME_DSDATA, + DelegationSignerData.create(12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B"))), + ImmutableSet.of( + SOME_DSDATA, + DelegationSignerData.create(12345, 3, 1, base16().decode("38EC35D5B3A34B33C99B")))); } @Test @@ -330,12 +359,13 @@ public class DomainApplicationUpdateFlowTest ImmutableSet.of(SOME_DSDATA)); } - private void doSecDnsFailingTest(Class expectedException, String xmlFilename) - throws Exception { + private void doSecDnsFailingTest( + Class expectedException, String xmlFilename) throws Exception { setEppInput(xmlFilename); persistReferencedEntities(); persistNewApplication(); - assertThrows(expectedException, this::runFlow); + EppException thrown = expectThrows(expectedException, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -352,40 +382,40 @@ public class DomainApplicationUpdateFlowTest @Test public void testFailure_secDnsUrgentNotSupported() throws Exception { doSecDnsFailingTest( - UrgentAttributeNotSupportedException.class, - "domain_update_sunrise_dsdata_urgent.xml"); + UrgentAttributeNotSupportedException.class, "domain_update_sunrise_dsdata_urgent.xml"); } @Test public void testFailure_secDnsChangeNotSupported() throws Exception { doSecDnsFailingTest( - MaxSigLifeChangeNotSupportedException.class, - "domain_update_sunrise_maxsiglife.xml"); + MaxSigLifeChangeNotSupportedException.class, "domain_update_sunrise_maxsiglife.xml"); } @Test public void testFailure_secDnsTooManyDsRecords() throws Exception { ImmutableSet.Builder builder = new ImmutableSet.Builder<>(); for (int i = 0; i < 8; ++i) { - builder.add(DelegationSignerData.create(i, 2, 3, new byte[]{0, 1, 2})); + builder.add(DelegationSignerData.create(i, 2, 3, new byte[] {0, 1, 2})); } setEppInput("domain_update_sunrise_dsdata_add.xml"); persistResource(newApplicationBuilder().setDsData(builder.build()).build()); - assertThrows(TooManyDsRecordsException.class, this::runFlow); + EppException thrown = expectThrows(TooManyDsRecordsException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } private void modifyApplicationToHave13Nameservers() throws Exception { ImmutableSet.Builder> nameservers = new ImmutableSet.Builder<>(); for (int i = 1; i < 15; i++) { if (i != 2) { // Skip 2 since that's the one that the tests will add. - nameservers.add(Key.create(loadByForeignKey( - HostResource.class, String.format("ns%d.example.tld", i), clock.nowUtc()))); + nameservers.add( + Key.create( + loadByForeignKey( + HostResource.class, String.format("ns%d.example.tld", i), clock.nowUtc()))); } } - persistResource(reloadDomainApplication().asBuilder() - .setNameservers(nameservers.build()) - .build()); + persistResource( + reloadDomainApplication().asBuilder().setNameservers(nameservers.build()).build()); } @Test @@ -395,20 +425,23 @@ public class DomainApplicationUpdateFlowTest // Modify application to have 13 nameservers. We will then remove one and add one in the test. modifyApplicationToHave13Nameservers(); setEppInput("domain_update_sunrise_add_nameserver.xml"); - assertThrows(TooManyNameserversException.class, this::runFlow); + EppException thrown = expectThrows(TooManyNameserversException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_wrongExtension() throws Exception { setEppInput("domain_update_sunrise_wrong_extension.xml"); - assertThrows(UnimplementedExtensionException.class, this::runFlow); + EppException thrown = expectThrows(UnimplementedExtensionException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_applicationDomainNameMismatch() throws Exception { persistReferencedEntities(); persistResource(newApplicationBuilder().setFullyQualifiedDomainName("something.tld").build()); - assertThrows(ApplicationDomainNameMismatchException.class, this::runFlow); + EppException thrown = expectThrows(ApplicationDomainNameMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -432,16 +465,22 @@ public class DomainApplicationUpdateFlowTest public void testFailure_clientUpdateProhibited() throws Exception { setEppInput("domain_update_sunrise_authinfo.xml"); persistReferencedEntities(); - persistResource(newApplicationBuilder().setStatusValues( - ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)).build()); - assertThrows(ResourceHasClientUpdateProhibitedException.class, this::runFlow); + persistResource( + newApplicationBuilder() + .setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)) + .build()); + EppException thrown = + expectThrows(ResourceHasClientUpdateProhibitedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_serverUpdateProhibited() throws Exception { persistReferencedEntities(); - persistResource(newApplicationBuilder().setStatusValues( - ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED)).build()); + persistResource( + newApplicationBuilder() + .setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED)) + .build()); ResourceStatusProhibitsOperationException thrown = expectThrows(ResourceStatusProhibitsOperationException.class, this::runFlow); assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited"); @@ -450,7 +489,9 @@ public class DomainApplicationUpdateFlowTest private void doIllegalApplicationStatusTest(ApplicationStatus status) throws Exception { persistReferencedEntities(); persistResource(newApplicationBuilder().setApplicationStatus(status).build()); - assertThrows(ApplicationStatusProhibitsUpdateException.class, this::runFlow); + EppException thrown = + expectThrows(ApplicationStatusProhibitsUpdateException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -497,10 +538,18 @@ public class DomainApplicationUpdateFlowTest persistNewApplication(); // Add a tech contact to the persisted entity, which should cause the flow to fail when it tries // to add "mak21" as a second tech contact. - persistResource(reloadDomainApplication().asBuilder().setContacts(ImmutableSet.of( - DesignatedContact.create(Type.TECH, Key.create( - loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))).build()); - assertThrows(DuplicateContactForRoleException.class, this::runFlow); + persistResource( + reloadDomainApplication() + .asBuilder() + .setContacts( + ImmutableSet.of( + DesignatedContact.create( + Type.TECH, + Key.create( + loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))) + .build()); + EppException thrown = expectThrows(DuplicateContactForRoleException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -508,10 +557,10 @@ public class DomainApplicationUpdateFlowTest setEppInput("domain_update_sunrise_prohibited_status.xml"); persistReferencedEntities(); persistNewApplication(); - assertThrows(StatusNotClientSettableException.class, this::runFlow); + EppException thrown = expectThrows(StatusNotClientSettableException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } - @Test public void testSuccess_superuserProhibitedStatusValue() throws Exception { setEppInput("domain_update_sunrise_prohibited_status.xml"); @@ -519,9 +568,7 @@ public class DomainApplicationUpdateFlowTest persistNewApplication(); clock.advanceOneMilli(); runFlowAssertResponse( - CommitMode.LIVE, - UserPrivileges.SUPERUSER, - loadFile("domain_update_response.xml")); + CommitMode.LIVE, UserPrivileges.SUPERUSER, loadFile("domain_update_response.xml")); } @Test @@ -529,7 +576,8 @@ public class DomainApplicationUpdateFlowTest setEppInput("domain_update_sunrise_duplicate_contact.xml"); persistReferencedEntities(); persistNewApplication(); - assertThrows(DuplicateContactForRoleException.class, this::runFlow); + EppException thrown = expectThrows(DuplicateContactForRoleException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -538,7 +586,8 @@ public class DomainApplicationUpdateFlowTest persistReferencedEntities(); persistNewApplication(); // We need to test for missing type, but not for invalid - the schema enforces that for us. - assertThrows(MissingContactTypeException.class, this::runFlow); + EppException thrown = expectThrows(MissingContactTypeException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -546,7 +595,8 @@ public class DomainApplicationUpdateFlowTest sessionMetadata.setClientId("NewRegistrar"); persistReferencedEntities(); persistApplication(); - assertThrows(ResourceNotOwnedException.class, this::runFlow); + EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -565,7 +615,8 @@ public class DomainApplicationUpdateFlowTest loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); persistReferencedEntities(); persistApplication(); - assertThrows(NotAuthorizedForTldException.class, this::runFlow); + EppException thrown = expectThrows(NotAuthorizedForTldException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -583,48 +634,62 @@ public class DomainApplicationUpdateFlowTest public void testFailure_sameNameserverAddedAndRemoved() throws Exception { setEppInput("domain_update_sunrise_add_remove_same_host.xml"); persistReferencedEntities(); - persistResource(newApplicationBuilder() - .setNameservers(ImmutableSet.of(Key.create( - loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())))) - .build()); - assertThrows(AddRemoveSameValueException.class, this::runFlow); + persistResource( + newApplicationBuilder() + .setNameservers( + ImmutableSet.of( + Key.create( + loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())))) + .build()); + EppException thrown = expectThrows(AddRemoveSameValueException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_sameContactAddedAndRemoved() throws Exception { setEppInput("domain_update_sunrise_add_remove_same_contact.xml"); persistReferencedEntities(); - persistResource(newApplicationBuilder() - .setContacts(ImmutableSet.of(DesignatedContact.create( - Type.TECH, - Key.create( - loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))))) - .build()); - assertThrows(AddRemoveSameValueException.class, this::runFlow); + persistResource( + newApplicationBuilder() + .setContacts( + ImmutableSet.of( + DesignatedContact.create( + Type.TECH, + Key.create( + loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))))) + .build()); + EppException thrown = expectThrows(AddRemoveSameValueException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_removeAdmin() throws Exception { setEppInput("domain_update_sunrise_remove_admin.xml"); persistReferencedEntities(); - persistResource(newApplicationBuilder() - .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), - DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) - .build()); - assertThrows(MissingAdminContactException.class, this::runFlow); + persistResource( + newApplicationBuilder() + .setContacts( + ImmutableSet.of( + DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), + DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) + .build()); + EppException thrown = expectThrows(MissingAdminContactException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testFailure_removeTech() throws Exception { setEppInput("domain_update_sunrise_remove_tech.xml"); persistReferencedEntities(); - persistResource(newApplicationBuilder() - .setContacts(ImmutableSet.of( - DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), - DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) - .build()); - assertThrows(MissingTechnicalContactException.class, this::runFlow); + persistResource( + newApplicationBuilder() + .setContacts( + ImmutableSet.of( + DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), + DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) + .build()); + EppException thrown = expectThrows(MissingTechnicalContactException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -632,11 +697,13 @@ public class DomainApplicationUpdateFlowTest persistReferencedEntities(); persistApplication(); persistResource( - Registry.get("tld").asBuilder() + Registry.get("tld") + .asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("contact1234")) .build()); clock.advanceOneMilli(); - assertThrows(RegistrantNotAllowedException.class, this::runFlow); + EppException thrown = expectThrows(RegistrantNotAllowedException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -644,17 +711,20 @@ public class DomainApplicationUpdateFlowTest persistReferencedEntities(); persistApplication(); persistResource( - Registry.get("tld").asBuilder() + Registry.get("tld") + .asBuilder() .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo")) .build()); clock.advanceOneMilli(); - assertThrows(NameserversNotAllowedForTldException.class, this::runFlow); + EppException thrown = expectThrows(NameserversNotAllowedForTldException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test public void testSuccess_nameserverAndRegistrantWhitelisted() throws Exception { persistResource( - Registry.get("tld").asBuilder() + Registry.get("tld") + .asBuilder() .setAllowedRegistrantContactIds(ImmutableSet.of("sh8013")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.tld")) .build()); @@ -675,8 +745,10 @@ public class DomainApplicationUpdateFlowTest ImmutableSet.of("ns1.example.tld", "ns2.example.tld")) .build()); clock.advanceOneMilli(); - assertThrows( - NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, this::runFlow); + EppException thrown = + expectThrows( + NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -747,8 +819,10 @@ public class DomainApplicationUpdateFlowTest "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns2.example.tld")) .build()); clock.advanceOneMilli(); - assertThrows( - NameserversNotSpecifiedForNameserverRestrictedDomainException.class, this::runFlow); + EppException thrown = + expectThrows( + NameserversNotSpecifiedForNameserverRestrictedDomainException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test @@ -842,7 +916,8 @@ public class DomainApplicationUpdateFlowTest "domain_update_sunrise_fee.xml", ImmutableMap.of("DOMAIN", "non-free-update.tld", "AMOUNT", "12.00")); clock.advanceOneMilli(); - assertThrows(FeesMismatchException.class, this::runFlow); + EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow); + assertAboutEppExceptions().that(thrown).marshalsToXml(); } @Test