Automatically refactor more exception testing to use new JUnit rules

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179072309
This commit is contained in:
mcilwain 2017-12-14 11:40:04 -08:00 committed by Ben McIlwain
parent d5d29959b4
commit 9157930983
100 changed files with 3900 additions and 3192 deletions

View file

@ -39,7 +39,6 @@ import org.joda.time.DateTime;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -53,9 +52,6 @@ public class EppCommitLogsTest extends ShardableTestCase {
.withTaskQueue() .withTaskQueue()
.build(); .build();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule @Rule
public final InjectRule inject = new InjectRule(); public final InjectRule inject = new InjectRule();

View file

@ -17,14 +17,13 @@ package google.registry.flows;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.EppXmlTransformer.unmarshal; import static google.registry.flows.EppXmlTransformer.unmarshal;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.ResourceUtils.readResourceBytes; import static google.registry.util.ResourceUtils.readResourceBytes;
import google.registry.model.eppinput.EppInput; import google.registry.model.eppinput.EppInput;
import google.registry.model.eppoutput.EppOutput; import google.registry.model.eppoutput.EppOutput;
import google.registry.testing.ShardableTestCase; import google.registry.testing.ShardableTestCase;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -32,9 +31,6 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class EppXmlTransformerTest extends ShardableTestCase { public class EppXmlTransformerTest extends ShardableTestCase {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testUnmarshalingEppInput() throws Exception { public void testUnmarshalingEppInput() throws Exception {
EppInput input = unmarshal( EppInput input = unmarshal(
@ -44,8 +40,11 @@ public class EppXmlTransformerTest extends ShardableTestCase {
@Test @Test
public void testUnmarshalingWrongClassThrows() throws Exception { public void testUnmarshalingWrongClassThrows() throws Exception {
thrown.expect(ClassCastException.class); assertThrows(
EppXmlTransformer.unmarshal( ClassCastException.class,
EppOutput.class, readResourceBytes(getClass(), "testdata/contact_info.xml").read()); () ->
EppXmlTransformer.unmarshal(
EppOutput.class,
readResourceBytes(getClass(), "testdata/contact_info.xml").read()));
} }
} }

View file

@ -15,6 +15,7 @@
package google.registry.flows; package google.registry.flows;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -38,7 +39,6 @@ import java.util.logging.LogRecord;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -50,10 +50,6 @@ public class ExtensionManagerTest {
public final AppEngineRule appEngine = AppEngineRule.builder() public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore() .withDatastore()
.build(); .build();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testDuplicateExtensionsForbidden() throws Exception { public void testDuplicateExtensionsForbidden() throws Exception {
ExtensionManager manager = new TestInstanceBuilder() ExtensionManager manager = new TestInstanceBuilder()
@ -65,8 +61,7 @@ public class ExtensionManagerTest {
MetadataExtension.class) MetadataExtension.class)
.build(); .build();
manager.register(MetadataExtension.class, LaunchCreateExtension.class); manager.register(MetadataExtension.class, LaunchCreateExtension.class);
thrown.expect(UnsupportedRepeatedExtensionException.class); assertThrows(UnsupportedRepeatedExtensionException.class, () -> manager.validate());
manager.validate();
} }
@Test @Test
@ -97,8 +92,7 @@ public class ExtensionManagerTest {
.setSuppliedExtensions(FeeInfoCommandExtensionV06.class) .setSuppliedExtensions(FeeInfoCommandExtensionV06.class)
.build(); .build();
manager.register(FeeInfoCommandExtensionV06.class); manager.register(FeeInfoCommandExtensionV06.class);
thrown.expect(UndeclaredServiceExtensionException.class); assertThrows(UndeclaredServiceExtensionException.class, () -> manager.validate());
manager.validate();
} }
@Test @Test
@ -131,8 +125,7 @@ public class ExtensionManagerTest {
.setSuppliedExtensions(MetadataExtension.class) .setSuppliedExtensions(MetadataExtension.class)
.build(); .build();
manager.register(MetadataExtension.class); manager.register(MetadataExtension.class);
thrown.expect(OnlyToolCanPassMetadataException.class); assertThrows(OnlyToolCanPassMetadataException.class, () -> manager.validate());
manager.validate();
} }
@Test @Test
@ -156,8 +149,7 @@ public class ExtensionManagerTest {
.setIsSuperuser(false) .setIsSuperuser(false)
.build(); .build();
manager.register(DomainTransferRequestSuperuserExtension.class); manager.register(DomainTransferRequestSuperuserExtension.class);
thrown.expect(UnauthorizedForSuperuserExtensionException.class); assertThrows(UnauthorizedForSuperuserExtensionException.class, () -> manager.validate());
manager.validate();
} }
@Test @Test
@ -169,8 +161,7 @@ public class ExtensionManagerTest {
.setIsSuperuser(true) .setIsSuperuser(true)
.build(); .build();
manager.register(DomainTransferRequestSuperuserExtension.class); manager.register(DomainTransferRequestSuperuserExtension.class);
thrown.expect(UnauthorizedForSuperuserExtensionException.class); assertThrows(UnauthorizedForSuperuserExtensionException.class, () -> manager.validate());
manager.validate();
} }
@Test @Test
@ -180,8 +171,7 @@ public class ExtensionManagerTest {
.setDeclaredUris() .setDeclaredUris()
.setSuppliedExtensions(LaunchCreateExtension.class) .setSuppliedExtensions(LaunchCreateExtension.class)
.build(); .build();
thrown.expect(UnimplementedExtensionException.class); assertThrows(UnimplementedExtensionException.class, () -> manager.validate());
manager.validate();
} }
/** A builder for a test-ready {@link ExtensionManager} instance. */ /** A builder for a test-ready {@link ExtensionManager} instance. */

View file

@ -63,7 +63,6 @@ import java.util.Map;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -87,9 +86,6 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
.withTaskQueue() .withTaskQueue()
.build(); .build();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule @Rule
public final InjectRule inject = new InjectRule(); public final InjectRule inject = new InjectRule();

View file

@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.tmch.ClaimsListShardTest.createTestClaimsListShard; import static google.registry.model.tmch.ClaimsListShardTest.createTestClaimsListShard;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.LogsSubject.assertAboutLogs; import static google.registry.testing.LogsSubject.assertAboutLogs;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
@ -131,8 +132,7 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
@Test @Test
public void testRequiresLogin() throws Exception { public void testRequiresLogin() throws Exception {
sessionMetadata.setClientId(null); sessionMetadata.setClientId(null);
thrown.expect(NotLoggedInException.class); assertThrows(NotLoggedInException.class, () -> runFlow());
runFlow();
} }
/** /**

View file

@ -15,37 +15,34 @@
package google.registry.flows; package google.registry.flows;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.BadRequestException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
/** Unit tests for {@link TlsCredentials}. */ /** Unit tests for {@link TlsCredentials}. */
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public final class TlsCredentialsTest { public final class TlsCredentialsTest {
@Rule public final ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testProvideClientCertificateHash() { public void testProvideClientCertificateHash() {
HttpServletRequest req = mock(HttpServletRequest.class); HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getHeader("X-SSL-Certificate")).thenReturn("data"); when(req.getHeader("X-SSL-Certificate")).thenReturn("data");
assertThat(TlsCredentials.EppTlsModule.provideClientCertificateHash(req)) assertThat(TlsCredentials.EppTlsModule.provideClientCertificateHash(req)).isEqualTo("data");
.isEqualTo("data");
} }
@Test @Test
public void testProvideClientCertificateHash_missing() { public void testProvideClientCertificateHash_missing() {
thrown.expect(BadRequestException.class);
thrown.expectMessage("Missing header: X-SSL-Certificate");
HttpServletRequest req = mock(HttpServletRequest.class); HttpServletRequest req = mock(HttpServletRequest.class);
TlsCredentials.EppTlsModule.provideClientCertificateHash(req); BadRequestException thrown =
expectThrows(
BadRequestException.class,
() -> TlsCredentials.EppTlsModule.provideClientCertificateHash(req));
assertThat(thrown).hasMessageThat().contains("Missing header: X-SSL-Certificate");
} }
@Test @Test
@ -58,10 +55,12 @@ public final class TlsCredentialsTest {
@Test @Test
public void testProvideRequestedServername_missing() { public void testProvideRequestedServername_missing() {
thrown.expect(BadRequestException.class);
thrown.expectMessage("Missing header: X-Requested-Servername-SNI");
HttpServletRequest req = mock(HttpServletRequest.class); HttpServletRequest req = mock(HttpServletRequest.class);
TlsCredentials.EppTlsModule.provideRequestedServername(req); BadRequestException thrown =
expectThrows(
BadRequestException.class,
() -> TlsCredentials.EppTlsModule.provideRequestedServername(req));
assertThat(thrown).hasMessageThat().contains("Missing header: X-Requested-Servername-SNI");
} }
} }

View file

@ -17,6 +17,7 @@ package google.registry.flows.contact;
import static google.registry.model.eppoutput.CheckData.ContactCheck.create; import static google.registry.model.eppoutput.CheckData.ContactCheck.create;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact;
import static google.registry.testing.JUnitBackports.assertThrows;
import google.registry.flows.ResourceCheckFlowTestCase; import google.registry.flows.ResourceCheckFlowTestCase;
import google.registry.flows.exceptions.TooManyResourceChecksException; import google.registry.flows.exceptions.TooManyResourceChecksException;
@ -76,8 +77,7 @@ public class ContactCheckFlowTest
@Test @Test
public void testTooManyIds() throws Exception { public void testTooManyIds() throws Exception {
setEppInput("contact_check_51.xml"); setEppInput("contact_check_51.xml");
thrown.expect(TooManyResourceChecksException.class); assertThrows(TooManyResourceChecksException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -14,10 +14,13 @@
package google.registry.flows.contact; package google.registry.flows.contact;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.contact.ContactFlowUtils.BadInternationalizedPostalInfoException; import google.registry.flows.contact.ContactFlowUtils.BadInternationalizedPostalInfoException;
@ -66,10 +69,12 @@ public class ContactCreateFlowTest
@Test @Test
public void testFailure_alreadyExists() throws Exception { public void testFailure_alreadyExists() throws Exception {
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
thrown.expect(ResourceAlreadyExistsException.class); ResourceAlreadyExistsException thrown =
thrown.expectMessage( expectThrows(ResourceAlreadyExistsException.class, () -> runFlow());
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); assertThat(thrown)
runFlow(); .hasMessageThat()
.contains(
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
} }
@Test @Test
@ -81,15 +86,13 @@ public class ContactCreateFlowTest
@Test @Test
public void testFailure_nonAsciiInIntAddress() throws Exception { public void testFailure_nonAsciiInIntAddress() throws Exception {
setEppInput("contact_create_hebrew_int.xml"); setEppInput("contact_create_hebrew_int.xml");
thrown.expect(BadInternationalizedPostalInfoException.class); assertThrows(BadInternationalizedPostalInfoException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_declineDisclosure() throws Exception { public void testFailure_declineDisclosure() throws Exception {
setEppInput("contact_create_decline_disclosure.xml"); setEppInput("contact_create_decline_disclosure.xml");
thrown.expect(DeclineContactDisclosureFieldDisallowedPolicyException.class); assertThrows(DeclineContactDisclosureFieldDisallowedPolicyException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -23,6 +23,7 @@ import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -71,17 +72,17 @@ public class ContactDeleteFlowTest
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -116,8 +117,7 @@ public class ContactDeleteFlowTest
public void testFailure_unauthorizedClient() throws Exception { public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -142,8 +142,7 @@ public class ContactDeleteFlowTest
createTld("tld"); createTld("tld");
persistResource( persistResource(
newDomainResource("example.tld", persistActiveContact(getUniqueIdFromCommand()))); newDomainResource("example.tld", persistActiveContact(getUniqueIdFromCommand())));
thrown.expect(ResourceToDeleteIsReferencedException.class); assertThrows(ResourceToDeleteIsReferencedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -151,8 +150,7 @@ public class ContactDeleteFlowTest
createTld("tld"); createTld("tld");
persistResource( persistResource(
newDomainResource("example.tld", persistActiveContact(getUniqueIdFromCommand()))); newDomainResource("example.tld", persistActiveContact(getUniqueIdFromCommand())));
thrown.expect(ResourceToDeleteIsReferencedException.class); assertThrows(ResourceToDeleteIsReferencedException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -20,6 +20,7 @@ import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -163,17 +164,17 @@ public class ContactInfoFlowTest extends ResourceFlowTestCase<ContactInfoFlow, C
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistContactResource(false); persistContactResource(false);
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test

View file

@ -23,6 +23,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.getOnlyPollMessage; import static google.registry.testing.DatastoreHelper.getOnlyPollMessage;
import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@ -142,73 +144,76 @@ public class ContactTransferApproveFlowTest
contact.asBuilder() contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("contact_transfer_approve_with_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_approve_with_authinfo.xml"));
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_clientApproved() throws Exception { public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED); changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_clientRejected() throws Exception { public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED); changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_clientCancelled() throws Exception { public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED); changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_serverApproved() throws Exception { public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED); changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_serverCancelled() throws Exception { public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_gainingClient() throws Exception { public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar"); setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class); assertThrows(
doFailingTest("contact_transfer_approve.xml"); ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
thrown.expect(ResourceNotOwnedException.class); assertThrows(
doFailingTest("contact_transfer_approve.xml"); ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_deletedContact() throws Exception { public void testFailure_deletedContact() throws Exception {
contact = persistResource( contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("contact_transfer_approve.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_approve.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -216,9 +221,11 @@ public class ContactTransferApproveFlowTest
deleteResource(contact); deleteResource(contact);
contact = persistResource( contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("contact_transfer_approve.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_approve.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test

View file

@ -22,6 +22,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.getOnlyPollMessage; import static google.registry.testing.DatastoreHelper.getOnlyPollMessage;
import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@ -126,81 +128,86 @@ public class ContactTransferCancelFlowTest
contact.asBuilder() contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("contact_transfer_cancel_with_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_cancel_with_authinfo.xml"));
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_clientApproved() throws Exception { public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED); changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_clientRejected() throws Exception { public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED); changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_clientCancelled() throws Exception { public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED); changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_serverApproved() throws Exception { public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED); changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_serverCancelled() throws Exception { public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_sponsoringClient() throws Exception { public void testFailure_sponsoringClient() throws Exception {
setClientIdForFlow("TheRegistrar"); setClientIdForFlow("TheRegistrar");
thrown.expect(NotTransferInitiatorException.class); assertThrows(
doFailingTest("contact_transfer_cancel.xml"); NotTransferInitiatorException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
thrown.expect(NotTransferInitiatorException.class); assertThrows(
doFailingTest("contact_transfer_cancel.xml"); NotTransferInitiatorException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_deletedContact() throws Exception { public void testFailure_deletedContact() throws Exception {
contact = persistResource( contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("contact_transfer_cancel.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_cancel.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_nonexistentContact() throws Exception { public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact); deleteResource(contact);
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("contact_transfer_cancel.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_cancel.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test

View file

@ -14,10 +14,13 @@
package google.registry.flows.contact; package google.registry.flows.contact;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.deleteResource; import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@ -138,8 +141,9 @@ public class ContactTransferQueryFlowTest
contact.asBuilder() contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("contact_transfer_query_with_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_query_with_authinfo.xml"));
} }
@Test @Test
@ -147,39 +151,43 @@ public class ContactTransferQueryFlowTest
// Set the contact to a different ROID, but don't persist it; this is just so the substitution // Set the contact to a different ROID, but don't persist it; this is just so the substitution
// code above will write the wrong ROID into the file. // code above will write the wrong ROID into the file.
contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build(); contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build();
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("contact_transfer_query_with_roid.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_query_with_roid.xml"));
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
thrown.expect(NoTransferHistoryToQueryException.class); assertThrows(
doFailingTest("contact_transfer_query.xml"); NoTransferHistoryToQueryException.class, () -> doFailingTest("contact_transfer_query.xml"));
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
thrown.expect(NotAuthorizedToViewTransferException.class); assertThrows(
doFailingTest("contact_transfer_query.xml"); NotAuthorizedToViewTransferException.class,
() -> doFailingTest("contact_transfer_query.xml"));
} }
@Test @Test
public void testFailure_deletedContact() throws Exception { public void testFailure_deletedContact() throws Exception {
contact = persistResource( contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("contact_transfer_query.xml"); ResourceDoesNotExistException.class, () -> doFailingTest("contact_transfer_query.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_nonexistentContact() throws Exception { public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact); deleteResource(contact);
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("contact_transfer_query.xml"); ResourceDoesNotExistException.class, () -> doFailingTest("contact_transfer_query.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test

View file

@ -22,6 +22,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.getOnlyPollMessage; import static google.registry.testing.DatastoreHelper.getOnlyPollMessage;
import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@ -141,81 +143,86 @@ public class ContactTransferRejectFlowTest
contact.asBuilder() contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("contact_transfer_reject_with_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_reject_with_authinfo.xml"));
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_clientApproved() throws Exception { public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED); changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_clientRejected() throws Exception { public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED); changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_clientCancelled() throws Exception { public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED); changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_serverApproved() throws Exception { public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED); changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_serverCancelled() throws Exception { public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_gainingClient() throws Exception { public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar"); setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class); assertThrows(
doFailingTest("contact_transfer_reject.xml"); ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
thrown.expect(ResourceNotOwnedException.class); assertThrows(
doFailingTest("contact_transfer_reject.xml"); ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_deletedContact() throws Exception { public void testFailure_deletedContact() throws Exception {
contact = persistResource( contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("contact_transfer_reject.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_reject.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_nonexistentContact() throws Exception { public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact); deleteResource(contact);
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("contact_transfer_reject.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_reject.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test

View file

@ -28,6 +28,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -154,8 +156,9 @@ public class ContactTransferRequestFlowTest
@Test @Test
public void testFailure_noAuthInfo() throws Exception { public void testFailure_noAuthInfo() throws Exception {
thrown.expect(MissingTransferRequestAuthInfoException.class); assertThrows(
doFailingTest("contact_transfer_request_no_authinfo.xml"); MissingTransferRequestAuthInfoException.class,
() -> doFailingTest("contact_transfer_request_no_authinfo.xml"));
} }
@Test @Test
@ -165,8 +168,8 @@ public class ContactTransferRequestFlowTest
contact.asBuilder() contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("contact_transfer_request.xml"); BadAuthInfoForResourceException.class, () -> doFailingTest("contact_transfer_request.xml"));
} }
@Test @Test
@ -208,59 +211,69 @@ public class ContactTransferRequestFlowTest
.setPendingTransferExpirationTime(clock.nowUtc().plusDays(1)) .setPendingTransferExpirationTime(clock.nowUtc().plusDays(1))
.build()) .build())
.build()); .build());
thrown.expect(AlreadyPendingTransferException.class); assertThrows(
doFailingTest("contact_transfer_request.xml"); AlreadyPendingTransferException.class, () -> doFailingTest("contact_transfer_request.xml"));
} }
@Test @Test
public void testFailure_sponsoringClient() throws Exception { public void testFailure_sponsoringClient() throws Exception {
setClientIdForFlow("TheRegistrar"); setClientIdForFlow("TheRegistrar");
thrown.expect(ObjectAlreadySponsoredException.class); assertThrows(
doFailingTest("contact_transfer_request.xml"); ObjectAlreadySponsoredException.class, () -> doFailingTest("contact_transfer_request.xml"));
} }
@Test @Test
public void testFailure_deletedContact() throws Exception { public void testFailure_deletedContact() throws Exception {
contact = persistResource( contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("contact_transfer_request.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_nonexistentContact() throws Exception { public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact); deleteResource(contact);
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("contact_transfer_request.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_clientTransferProhibited() throws Exception { public void testFailure_clientTransferProhibited() throws Exception {
contact = persistResource( contact = persistResource(
contact.asBuilder().addStatusValue(StatusValue.CLIENT_TRANSFER_PROHIBITED).build()); contact.asBuilder().addStatusValue(StatusValue.CLIENT_TRANSFER_PROHIBITED).build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("clientTransferProhibited"); expectThrows(
doFailingTest("contact_transfer_request.xml"); ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("clientTransferProhibited");
} }
@Test @Test
public void testFailure_serverTransferProhibited() throws Exception { public void testFailure_serverTransferProhibited() throws Exception {
contact = persistResource( contact = persistResource(
contact.asBuilder().addStatusValue(StatusValue.SERVER_TRANSFER_PROHIBITED).build()); contact.asBuilder().addStatusValue(StatusValue.SERVER_TRANSFER_PROHIBITED).build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("serverTransferProhibited"); expectThrows(
doFailingTest("contact_transfer_request.xml"); ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("serverTransferProhibited");
} }
@Test @Test
public void testFailure_pendingDelete() throws Exception { public void testFailure_pendingDelete() throws Exception {
contact = persistResource( contact = persistResource(
contact.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build()); contact.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("pendingDelete"); expectThrows(
doFailingTest("contact_transfer_request.xml"); ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("pendingDelete");
} }
@Test @Test

View file

@ -14,12 +14,15 @@
package google.registry.flows.contact; package google.registry.flows.contact;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.ContactResourceSubject.assertAboutContacts; import static google.registry.testing.ContactResourceSubject.assertAboutContacts;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.newContactResource; import static google.registry.testing.DatastoreHelper.newContactResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -253,25 +256,24 @@ public class ContactUpdateFlowTest
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_statusValueNotClientSettable() throws Exception { public void testFailure_statusValueNotClientSettable() throws Exception {
setEppInput("contact_update_prohibited_status.xml"); setEppInput("contact_update_prohibited_status.xml");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
thrown.expect(StatusNotClientSettableException.class); assertThrows(StatusNotClientSettableException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -289,8 +291,7 @@ public class ContactUpdateFlowTest
public void testFailure_unauthorizedClient() throws Exception { public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -337,8 +338,7 @@ public class ContactUpdateFlowTest
newContactResource(getUniqueIdFromCommand()).asBuilder() newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)) .setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build()); .build());
thrown.expect(ResourceHasClientUpdateProhibitedException.class); assertThrows(ResourceHasClientUpdateProhibitedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -347,9 +347,9 @@ public class ContactUpdateFlowTest
newContactResource(getUniqueIdFromCommand()).asBuilder() newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED)) .setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED))
.build()); .build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("serverUpdateProhibited"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited");
} }
@Test @Test
@ -358,9 +358,9 @@ public class ContactUpdateFlowTest
newContactResource(getUniqueIdFromCommand()).asBuilder() newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.build()); .build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("pendingDelete"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("pendingDelete");
} }
@Test @Test
@ -373,24 +373,21 @@ public class ContactUpdateFlowTest
public void testFailure_nonAsciiInIntAddress() throws Exception { public void testFailure_nonAsciiInIntAddress() throws Exception {
setEppInput("contact_update_hebrew_int.xml"); setEppInput("contact_update_hebrew_int.xml");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
thrown.expect(BadInternationalizedPostalInfoException.class); assertThrows(BadInternationalizedPostalInfoException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_declineDisclosure() throws Exception { public void testFailure_declineDisclosure() throws Exception {
setEppInput("contact_update_decline_disclosure.xml"); setEppInput("contact_update_decline_disclosure.xml");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
thrown.expect(DeclineContactDisclosureFieldDisallowedPolicyException.class); assertThrows(DeclineContactDisclosureFieldDisallowedPolicyException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_addRemoveSameValue() throws Exception { public void testFailure_addRemoveSameValue() throws Exception {
setEppInput("contact_update_add_remove_same.xml"); setEppInput("contact_update_add_remove_same.xml");
persistActiveContact(getUniqueIdFromCommand()); persistActiveContact(getUniqueIdFromCommand());
thrown.expect(AddRemoveSameValueException.class); assertThrows(AddRemoveSameValueException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -30,6 +30,8 @@ import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
@ -253,9 +255,9 @@ public class DomainAllocateFlowTest
.setAllowedRegistrantContactIds(ImmutableSet.of("jd1234")) .setAllowedRegistrantContactIds(ImmutableSet.of("jd1234"))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net"))
.build()); .build());
thrown.expect(NameserversNotAllowedForTldException.class); NameserversNotAllowedForTldException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForTldException.class, () -> runFlowAsSuperuser());
runFlowAsSuperuser(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -268,9 +270,9 @@ public class DomainAllocateFlowTest
.setAllowedFullyQualifiedHostNames( .setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns1.example.net", "ns2.example.net")) ImmutableSet.of("ns1.example.net", "ns2.example.net"))
.build()); .build());
thrown.expect(RegistrantNotAllowedException.class); RegistrantNotAllowedException thrown =
thrown.expectMessage("jd1234"); expectThrows(RegistrantNotAllowedException.class, () -> runFlowAsSuperuser());
runFlowAsSuperuser(); assertThat(thrown).hasMessageThat().contains("jd1234");
} }
@Test @Test
@ -283,8 +285,9 @@ public class DomainAllocateFlowTest
.setAllowedRegistrantContactIds(ImmutableSet.of("jd1234")) .setAllowedRegistrantContactIds(ImmutableSet.of("jd1234"))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.net, ns2.example.net")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.net, ns2.example.net"))
.build()); .build());
thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class); assertThrows(
runFlowAsSuperuser(); NameserversNotSpecifiedForTldWithNameserverWhitelistException.class,
() -> runFlowAsSuperuser());
} }
@Test @Test
@ -313,9 +316,9 @@ public class DomainAllocateFlowTest
"reserved", "reserved",
"example-one,NAMESERVER_RESTRICTED," + "ns2.example.net:ns3.example.net")) "example-one,NAMESERVER_RESTRICTED," + "ns2.example.net:ns3.example.net"))
.build()); .build());
thrown.expect(NameserversNotAllowedForDomainException.class); NameserversNotAllowedForDomainException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlowAsSuperuser());
runFlowAsSuperuser(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -330,8 +333,9 @@ public class DomainAllocateFlowTest
"reserved", "reserved",
"example-one,NAMESERVER_RESTRICTED," + "ns2.example.net:ns3.example.net")) "example-one,NAMESERVER_RESTRICTED," + "ns2.example.net:ns3.example.net"))
.build()); .build());
thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class); assertThrows(
runFlowAsSuperuser(); NameserversNotSpecifiedForNameserverRestrictedDomainException.class,
() -> runFlowAsSuperuser());
} }
@Test @Test
@ -366,9 +370,9 @@ public class DomainAllocateFlowTest
.setAllowedFullyQualifiedHostNames( .setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns1.example.net", "ns2.example.net", "ns3.example.net")) ImmutableSet.of("ns1.example.net", "ns2.example.net", "ns3.example.net"))
.build()); .build());
thrown.expect(NameserversNotAllowedForDomainException.class); NameserversNotAllowedForDomainException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlowAsSuperuser());
runFlowAsSuperuser(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -385,9 +389,9 @@ public class DomainAllocateFlowTest
.setAllowedFullyQualifiedHostNames( .setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns4.example.net", "ns2.example.net", "ns3.example.net")) ImmutableSet.of("ns4.example.net", "ns2.example.net", "ns3.example.net"))
.build()); .build());
thrown.expect(NameserversNotAllowedForTldException.class); NameserversNotAllowedForTldException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForTldException.class, () -> runFlowAsSuperuser());
runFlowAsSuperuser(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -571,8 +575,7 @@ public class DomainAllocateFlowTest
public void testFailure_alreadyExists() throws Exception { public void testFailure_alreadyExists() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD); setupDomainApplication("tld", TldState.QUIET_PERIOD);
persistActiveDomain(getUniqueIdFromCommand()); persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(ResourceAlreadyExistsException.class); assertThrows(ResourceAlreadyExistsException.class, () -> runFlowAsSuperuser());
runFlowAsSuperuser();
} }
@Test @Test
@ -607,8 +610,7 @@ public class DomainAllocateFlowTest
public void testFailure_applicationDeleted() throws Exception { public void testFailure_applicationDeleted() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD); setupDomainApplication("tld", TldState.QUIET_PERIOD);
persistResource(application.asBuilder().setDeletionTime(clock.nowUtc()).build()); persistResource(application.asBuilder().setDeletionTime(clock.nowUtc()).build());
thrown.expect(MissingApplicationException.class); assertThrows(MissingApplicationException.class, () -> runFlowAsSuperuser());
runFlowAsSuperuser();
} }
@Test @Test
@ -617,8 +619,7 @@ public class DomainAllocateFlowTest
persistResource(application.asBuilder() persistResource(application.asBuilder()
.setApplicationStatus(ApplicationStatus.REJECTED) .setApplicationStatus(ApplicationStatus.REJECTED)
.build()); .build());
thrown.expect(HasFinalStatusException.class); assertThrows(HasFinalStatusException.class, () -> runFlowAsSuperuser());
runFlowAsSuperuser();
} }
@Test @Test
@ -627,16 +628,14 @@ public class DomainAllocateFlowTest
persistResource(application.asBuilder() persistResource(application.asBuilder()
.setApplicationStatus(ApplicationStatus.ALLOCATED) .setApplicationStatus(ApplicationStatus.ALLOCATED)
.build()); .build());
thrown.expect(HasFinalStatusException.class); assertThrows(HasFinalStatusException.class, () -> runFlowAsSuperuser());
runFlowAsSuperuser();
} }
@Test @Test
public void testFailure_applicationDoesNotExist() throws Exception { public void testFailure_applicationDoesNotExist() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD); setupDomainApplication("tld", TldState.QUIET_PERIOD);
setEppInput("domain_allocate_bad_application_roid.xml"); setEppInput("domain_allocate_bad_application_roid.xml");
thrown.expect(MissingApplicationException.class); assertThrows(MissingApplicationException.class, () -> runFlowAsSuperuser());
runFlowAsSuperuser();
} }
@Test @Test
@ -645,16 +644,16 @@ public class DomainAllocateFlowTest
clock.advanceOneMilli(); clock.advanceOneMilli();
setEppInput("domain_allocate_no_nameservers.xml"); setEppInput("domain_allocate_no_nameservers.xml");
assertTransactionalFlow(true); assertTransactionalFlow(true);
thrown.expect(OnlySuperuserCanAllocateException.class); assertThrows(
runFlow(CommitMode.LIVE, UserPrivileges.NORMAL); OnlySuperuserCanAllocateException.class,
() -> runFlow(CommitMode.LIVE, UserPrivileges.NORMAL));
} }
@Test @Test
public void testFailure_max10Years() throws Exception { public void testFailure_max10Years() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD); setupDomainApplication("tld", TldState.QUIET_PERIOD);
setEppInput("domain_allocate_11_years.xml"); setEppInput("domain_allocate_11_years.xml");
thrown.expect(ExceedsMaxRegistrationYearsException.class); assertThrows(ExceedsMaxRegistrationYearsException.class, () -> runFlowAsSuperuser());
runFlowAsSuperuser();
} }
@Test @Test

View file

@ -34,6 +34,7 @@ import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.assertThrows; 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 google.registry.util.DateTimeUtils.START_OF_TIME;
import static java.util.Comparator.comparing; import static java.util.Comparator.comparing;
import static org.joda.money.CurrencyUnit.EUR; import static org.joda.money.CurrencyUnit.EUR;
@ -245,8 +246,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_encoded_signed_mark_corrupt.xml"); setEppInput("domain_create_sunrush_encoded_signed_mark_corrupt.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SignedMarkParsingErrorException.class); assertThrows(SignedMarkParsingErrorException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -255,8 +255,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_encoded_signed_mark_revoked_cert.xml"); setEppInput("domain_create_sunrush_encoded_signed_mark_revoked_cert.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SignedMarkCertificateRevokedException.class); assertThrows(SignedMarkCertificateRevokedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -267,8 +266,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli(); clock.advanceOneMilli();
clock.setTo(DateTime.parse("2022-01-01")); clock.setTo(DateTime.parse("2022-01-01"));
clock.setTo(DateTime.parse("2022-01-01")); clock.setTo(DateTime.parse("2022-01-01"));
thrown.expect(SignedMarkCertificateExpiredException.class); assertThrows(SignedMarkCertificateExpiredException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -278,8 +276,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
clock.setTo(DateTime.parse("2012-07-22T00:01:00Z")); clock.setTo(DateTime.parse("2012-07-22T00:01:00Z"));
thrown.expect(SignedMarkCertificateNotYetValidException.class); assertThrows(SignedMarkCertificateNotYetValidException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -296,8 +293,7 @@ public class DomainApplicationCreateFlowTest
public void verify(byte[] smdXml) throws GeneralSecurityException { public void verify(byte[] smdXml) throws GeneralSecurityException {
throw new GeneralSecurityException(); throw new GeneralSecurityException();
}}; }};
thrown.expect(SignedMarkCertificateInvalidException.class); assertThrows(SignedMarkCertificateInvalidException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -307,8 +303,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_encoded_signed_mark.xml"); setEppInput("domain_create_sunrush_encoded_signed_mark.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SignedMarkCertificateSignatureException.class); assertThrows(SignedMarkCertificateSignatureException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -317,8 +312,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_encoded_signed_mark_signature_corrupt.xml"); setEppInput("domain_create_sunrush_encoded_signed_mark_signature_corrupt.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SignedMarkSignatureException.class); assertThrows(SignedMarkSignatureException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -394,8 +388,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_allowedinsunrise.xml"); setEppInput("domain_create_landrush_allowedinsunrise.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(DomainReservedException.class); assertThrows(DomainReservedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -406,8 +399,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli(); clock.advanceOneMilli();
// Modify the Registrar to block premium names. // Modify the Registrar to block premium names.
persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build()); persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build());
thrown.expect(PremiumNameBlockedException.class); assertThrows(PremiumNameBlockedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -416,8 +408,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_premium.xml"); setEppInput("domain_create_landrush_premium.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(FeesRequiredForPremiumNameException.class); assertThrows(FeesRequiredForPremiumNameException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -526,8 +517,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
setEppInput("domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.6")); setEppInput("domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -537,8 +527,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli(); clock.advanceOneMilli();
setEppInput( setEppInput(
"domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.11")); "domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -548,8 +537,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli(); clock.advanceOneMilli();
setEppInput( setEppInput(
"domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.12")); "domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -559,8 +547,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli(); clock.advanceOneMilli();
setEppInput( setEppInput(
"domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.6")); "domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -570,8 +557,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli(); clock.advanceOneMilli();
setEppInput( setEppInput(
"domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.11")); "domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -581,8 +567,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli(); clock.advanceOneMilli();
setEppInput( setEppInput(
"domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.12")); "domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -591,8 +576,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.6")); setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -601,8 +585,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.11")); setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -611,8 +594,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.12")); setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -718,8 +700,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_without_marks.xml"); setEppInput("domain_create_sunrise_without_marks.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(LandrushApplicationDisallowedDuringSunriseException.class); assertThrows(LandrushApplicationDisallowedDuringSunriseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -734,8 +715,7 @@ public class DomainApplicationCreateFlowTest
.setState(State.SUSPENDED) .setState(State.SUSPENDED)
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(RegistrarMustBeActiveToCreateDomainsException.class); assertThrows(RegistrarMustBeActiveToCreateDomainsException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -744,8 +724,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_signed_mark.xml"); setEppInput("domain_create_landrush_signed_mark.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SunriseApplicationDisallowedDuringLandrushException.class); assertThrows(SunriseApplicationDisallowedDuringLandrushException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -753,8 +732,7 @@ public class DomainApplicationCreateFlowTest
SignedMarkRevocationList.create(clock.nowUtc(), ImmutableMap.of(SMD_ID, clock.nowUtc())).save(); SignedMarkRevocationList.create(clock.nowUtc(), ImmutableMap.of(SMD_ID, clock.nowUtc())).save();
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SignedMarkRevokedErrorException.class); assertThrows(SignedMarkRevokedErrorException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -763,8 +741,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_14_nameservers.xml"); setEppInput("domain_create_sunrush_14_nameservers.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(TooManyNameserversException.class); assertThrows(TooManyNameserversException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -772,8 +749,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_with_secdns_maxsiglife.xml"); setEppInput("domain_create_sunrise_with_secdns_maxsiglife.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(MaxSigLifeNotSupportedException.class); assertThrows(MaxSigLifeNotSupportedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -781,8 +757,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_signed_mark_with_secdns_9_records.xml"); setEppInput("domain_create_sunrise_signed_mark_with_secdns_9_records.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(TooManyDsRecordsException.class); assertThrows(TooManyDsRecordsException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -790,8 +765,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_wrong_extension.xml"); setEppInput("domain_create_sunrise_wrong_extension.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(UnimplementedExtensionException.class); assertThrows(UnimplementedExtensionException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -799,8 +773,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_signed_mark_reserved.xml"); setEppInput("domain_create_sunrise_signed_mark_reserved.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(DomainReservedException.class); assertThrows(DomainReservedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -852,8 +825,7 @@ public class DomainApplicationCreateFlowTest
persistSunriseApplication(); persistSunriseApplication();
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(UncontestedSunriseApplicationBlockedInLandrushException.class); assertThrows(UncontestedSunriseApplicationBlockedInLandrushException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -940,8 +912,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_lrp.xml"); setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(InvalidLrpTokenException.class); assertThrows(InvalidLrpTokenException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -961,8 +932,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_lrp.xml"); setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(InvalidLrpTokenException.class); assertThrows(InvalidLrpTokenException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -981,8 +951,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_lrp.xml"); setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(InvalidLrpTokenException.class); assertThrows(InvalidLrpTokenException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1037,8 +1006,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush.xml"); setEppInput("domain_create_landrush.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(InvalidLrpTokenException.class); assertThrows(InvalidLrpTokenException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1047,8 +1015,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_months.xml"); setEppInput("domain_create_landrush_months.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(BadPeriodUnitException.class); assertThrows(BadPeriodUnitException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1056,9 +1023,9 @@ public class DomainApplicationCreateFlowTest
persistActiveHost("ns1.example.net"); persistActiveHost("ns1.example.net");
persistActiveContact("jd1234"); persistActiveContact("jd1234");
persistActiveContact("sh8013"); persistActiveContact("sh8013");
thrown.expect(LinkedResourcesDoNotExistException.class); LinkedResourcesDoNotExistException thrown =
thrown.expectMessage("(ns2.example.net)"); expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(ns2.example.net)");
} }
@Test @Test
@ -1066,9 +1033,9 @@ public class DomainApplicationCreateFlowTest
persistActiveHost("ns1.example.net"); persistActiveHost("ns1.example.net");
persistActiveHost("ns2.example.net"); persistActiveHost("ns2.example.net");
persistActiveContact("jd1234"); persistActiveContact("jd1234");
thrown.expect(LinkedResourcesDoNotExistException.class); LinkedResourcesDoNotExistException thrown =
thrown.expectMessage("(sh8013)"); expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(sh8013)");
} }
@Test @Test
@ -1077,8 +1044,7 @@ public class DomainApplicationCreateFlowTest
createTld("foo", TldState.SUNRISE); createTld("foo", TldState.SUNRISE);
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(TldDoesNotExistException.class); assertThrows(TldDoesNotExistException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1086,8 +1052,7 @@ public class DomainApplicationCreateFlowTest
createTld("tld", TldState.PREDELEGATION); createTld("tld", TldState.PREDELEGATION);
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(BadCommandForRegistryPhaseException.class); assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1095,8 +1060,7 @@ public class DomainApplicationCreateFlowTest
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NotAuthorizedForTldException.class); assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1104,8 +1068,7 @@ public class DomainApplicationCreateFlowTest
createTld("tld", TldState.SUNRUSH); createTld("tld", TldState.SUNRUSH);
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(LaunchPhaseMismatchException.class); assertThrows(LaunchPhaseMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1113,8 +1076,7 @@ public class DomainApplicationCreateFlowTest
createTld("tld", TldState.QUIET_PERIOD); createTld("tld", TldState.QUIET_PERIOD);
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(BadCommandForRegistryPhaseException.class); assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1122,8 +1084,7 @@ public class DomainApplicationCreateFlowTest
createTld("tld", TldState.GENERAL_AVAILABILITY); createTld("tld", TldState.GENERAL_AVAILABILITY);
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(BadCommandForRegistryPhaseException.class); assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1131,8 +1092,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_signed_mark.xml"); setEppInput("domain_create_landrush_signed_mark.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(LaunchPhaseMismatchException.class); assertThrows(LaunchPhaseMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1189,8 +1149,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_duplicate_contact.xml"); setEppInput("domain_create_sunrise_duplicate_contact.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(DuplicateContactForRoleException.class); assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1199,8 +1158,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
// We need to test for missing type, but not for invalid - the schema enforces that for us. // We need to test for missing type, but not for invalid - the schema enforces that for us.
thrown.expect(MissingContactTypeException.class); assertThrows(MissingContactTypeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1208,8 +1166,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_no_matching_marks.xml"); setEppInput("domain_create_sunrise_no_matching_marks.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NoMarksFoundMatchingDomainException.class); assertThrows(NoMarksFoundMatchingDomainException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1218,8 +1175,7 @@ public class DomainApplicationCreateFlowTest
clock.setTo(DateTime.parse("2013-08-09T10:05:59Z").minusSeconds(1)); clock.setTo(DateTime.parse("2013-08-09T10:05:59Z").minusSeconds(1));
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NoMarksFoundMatchingDomainException.class); assertThrows(NoMarksFoundMatchingDomainException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1228,8 +1184,7 @@ public class DomainApplicationCreateFlowTest
clock.setTo(DateTime.parse("2017-07-23T22:00:00.000Z")); clock.setTo(DateTime.parse("2017-07-23T22:00:00.000Z"));
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NoMarksFoundMatchingDomainException.class); assertThrows(NoMarksFoundMatchingDomainException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1237,8 +1192,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_hex_encoding.xml"); setEppInput("domain_create_sunrise_hex_encoding.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(Base64RequiredForEncodedSignedMarksException.class); assertThrows(Base64RequiredForEncodedSignedMarksException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1246,8 +1200,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_bad_encoding.xml"); setEppInput("domain_create_sunrise_bad_encoding.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SignedMarkEncodingErrorException.class); assertThrows(SignedMarkEncodingErrorException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1255,8 +1208,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_bad_encoded_xml.xml"); setEppInput("domain_create_sunrise_bad_encoded_xml.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SignedMarkParsingErrorException.class); assertThrows(SignedMarkParsingErrorException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1265,8 +1217,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_bad_idn_minna.xml"); setEppInput("domain_create_sunrush_bad_idn_minna.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(InvalidIdnDomainLabelException.class); assertThrows(InvalidIdnDomainLabelException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1276,8 +1227,7 @@ public class DomainApplicationCreateFlowTest
persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY)); persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY));
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(InvalidTrademarkValidatorException.class); assertThrows(InvalidTrademarkValidatorException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1285,8 +1235,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_signed_mark.xml"); setEppInput("domain_create_sunrise_signed_mark.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SignedMarksMustBeEncodedException.class); assertThrows(SignedMarksMustBeEncodedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1294,8 +1243,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_code_with_mark.xml"); setEppInput("domain_create_sunrise_code_with_mark.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(UnsupportedMarkTypeException.class); assertThrows(UnsupportedMarkTypeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1303,8 +1251,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_empty_encoded_signed_mark.xml"); setEppInput("domain_create_sunrise_empty_encoded_signed_mark.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SignedMarkParsingErrorException.class); assertThrows(SignedMarkParsingErrorException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1313,8 +1260,7 @@ public class DomainApplicationCreateFlowTest
persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY)); persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY));
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NoticeCannotBeUsedWithSignedMarkException.class); assertThrows(NoticeCannotBeUsedWithSignedMarkException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1322,8 +1268,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_two_signed_marks.xml"); setEppInput("domain_create_sunrise_two_signed_marks.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(TooManySignedMarksException.class); assertThrows(TooManySignedMarksException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1333,8 +1278,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush.xml"); setEppInput("domain_create_sunrush.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(MissingClaimsNoticeException.class); assertThrows(MissingClaimsNoticeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1343,8 +1287,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_claim_notice.xml"); setEppInput("domain_create_landrush_claim_notice.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(UnexpectedClaimsNoticeException.class); assertThrows(UnexpectedClaimsNoticeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1356,8 +1299,7 @@ public class DomainApplicationCreateFlowTest
persistResource(Registry.get("tld").asBuilder() persistResource(Registry.get("tld").asBuilder()
.setClaimsPeriodEnd(clock.nowUtc()) .setClaimsPeriodEnd(clock.nowUtc())
.build()); .build());
thrown.expect(ClaimsPeriodEndedException.class); assertThrows(ClaimsPeriodEndedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1368,8 +1310,7 @@ public class DomainApplicationCreateFlowTest
persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY));
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(ExpiredClaimException.class); assertThrows(ExpiredClaimException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1380,8 +1321,7 @@ public class DomainApplicationCreateFlowTest
persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY));
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(AcceptedTooLongAgoException.class); assertThrows(AcceptedTooLongAgoException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1392,8 +1332,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_malformed_claim_notice1.xml"); setEppInput("domain_create_sunrush_malformed_claim_notice1.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(MalformedTcnIdException.class); assertThrows(MalformedTcnIdException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1404,8 +1343,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_malformed_claim_notice2.xml"); setEppInput("domain_create_sunrush_malformed_claim_notice2.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(MalformedTcnIdException.class); assertThrows(MalformedTcnIdException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1416,8 +1354,7 @@ public class DomainApplicationCreateFlowTest
persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY));
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(InvalidTcnIdChecksumException.class); assertThrows(InvalidTcnIdChecksumException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1428,8 +1365,7 @@ public class DomainApplicationCreateFlowTest
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1440,8 +1376,7 @@ public class DomainApplicationCreateFlowTest
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1452,8 +1387,7 @@ public class DomainApplicationCreateFlowTest
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1470,8 +1404,7 @@ public class DomainApplicationCreateFlowTest
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1488,8 +1421,7 @@ public class DomainApplicationCreateFlowTest
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1506,8 +1438,7 @@ public class DomainApplicationCreateFlowTest
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1516,8 +1447,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.6")); setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1526,8 +1456,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.11")); setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1536,8 +1465,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.12")); setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@ -1565,9 +1493,9 @@ public class DomainApplicationCreateFlowTest
persistResource(Registry.get("tld").asBuilder() persistResource(Registry.get("tld").asBuilder()
.setAllowedRegistrantContactIds(ImmutableSet.of("someone")) .setAllowedRegistrantContactIds(ImmutableSet.of("someone"))
.build()); .build());
thrown.expect(RegistrantNotAllowedException.class); RegistrantNotAllowedException thrown =
thrown.expectMessage("jd1234"); expectThrows(RegistrantNotAllowedException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("jd1234");
} }
@Test @Test
@ -1576,9 +1504,9 @@ public class DomainApplicationCreateFlowTest
persistResource(Registry.get("tld").asBuilder() persistResource(Registry.get("tld").asBuilder()
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net"))
.build()); .build());
thrown.expect(NameserversNotAllowedForTldException.class); NameserversNotAllowedForTldException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -1603,8 +1531,8 @@ public class DomainApplicationCreateFlowTest
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class); assertThrows(
runFlow(); NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, () -> runFlow());
} }
@Test @Test
@ -1638,9 +1566,9 @@ public class DomainApplicationCreateFlowTest
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForDomainException.class); NameserversNotAllowedForDomainException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -1656,8 +1584,8 @@ public class DomainApplicationCreateFlowTest
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class); assertThrows(
runFlow(); NameserversNotSpecifiedForNameserverRestrictedDomainException.class, () -> runFlow());
} }
@Test @Test
@ -1697,9 +1625,9 @@ public class DomainApplicationCreateFlowTest
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForDomainException.class); NameserversNotAllowedForDomainException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -1717,9 +1645,9 @@ public class DomainApplicationCreateFlowTest
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForTldException.class); NameserversNotAllowedForTldException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -1728,8 +1656,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_11_years.xml"); setEppInput("domain_create_landrush_11_years.xml");
persistContactsAndHosts(); persistContactsAndHosts();
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(ExceedsMaxRegistrationYearsException.class); assertThrows(ExceedsMaxRegistrationYearsException.class, () -> runFlow());
runFlow();
} }
private void doFailingDomainNameTest(String domainName, Class<? extends Throwable> exception) private void doFailingDomainNameTest(String domainName, Class<? extends Throwable> exception)

View file

@ -26,6 +26,8 @@ import static google.registry.testing.DatastoreHelper.newHostResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication; import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -123,9 +125,9 @@ public class DomainApplicationDeleteFlowTest
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -134,9 +136,9 @@ public class DomainApplicationDeleteFlowTest
.setRepoId("1-TLD") .setRepoId("1-TLD")
.setDeletionTime(clock.nowUtc().minusSeconds(1)) .setDeletionTime(clock.nowUtc().minusSeconds(1))
.build()); .build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -144,8 +146,7 @@ public class DomainApplicationDeleteFlowTest
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistResource( persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -163,8 +164,7 @@ public class DomainApplicationDeleteFlowTest
persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class); assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -186,8 +186,7 @@ public class DomainApplicationDeleteFlowTest
.setRepoId("1-TLD") .setRepoId("1-TLD")
.setPhase(LaunchPhase.SUNRISE) .setPhase(LaunchPhase.SUNRISE)
.build()); .build());
thrown.expect(SunriseApplicationCannotBeDeletedInLandrushException.class); assertThrows(SunriseApplicationCannotBeDeletedInLandrushException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -233,16 +232,14 @@ public class DomainApplicationDeleteFlowTest
setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld")); setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld"));
persistResource( persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(LaunchPhaseMismatchException.class); assertThrows(LaunchPhaseMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_wrongExtension() throws Exception { public void testFailure_wrongExtension() throws Exception {
setEppInput("domain_delete_application_wrong_extension.xml"); setEppInput("domain_delete_application_wrong_extension.xml");
persistActiveDomainApplication("example.tld"); persistActiveDomainApplication("example.tld");
thrown.expect(UnimplementedExtensionException.class); assertThrows(UnimplementedExtensionException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -250,8 +247,7 @@ public class DomainApplicationDeleteFlowTest
createTld("tld", TldState.PREDELEGATION); createTld("tld", TldState.PREDELEGATION);
persistResource( persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(BadCommandForRegistryPhaseException.class); assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -259,8 +255,7 @@ public class DomainApplicationDeleteFlowTest
createTld("tld", TldState.QUIET_PERIOD); createTld("tld", TldState.QUIET_PERIOD);
persistResource( persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(BadCommandForRegistryPhaseException.class); assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -268,8 +263,7 @@ public class DomainApplicationDeleteFlowTest
createTld("tld", TldState.GENERAL_AVAILABILITY); createTld("tld", TldState.GENERAL_AVAILABILITY);
persistResource( persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build()); newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(BadCommandForRegistryPhaseException.class); assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -306,8 +300,7 @@ public class DomainApplicationDeleteFlowTest
public void testFailure_applicationIdForDifferentDomain() throws Exception { public void testFailure_applicationIdForDifferentDomain() throws Exception {
persistResource( persistResource(
newDomainApplication("invalid.tld").asBuilder().setRepoId("1-TLD").build()); newDomainApplication("invalid.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(ApplicationDomainNameMismatchException.class); assertThrows(ApplicationDomainNameMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -22,6 +22,8 @@ import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -261,9 +263,9 @@ public class DomainApplicationInfoFlowTest
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -274,9 +276,9 @@ public class DomainApplicationInfoFlowTest
.setDeletionTime(clock.nowUtc().minusDays(1)) .setDeletionTime(clock.nowUtc().minusDays(1))
.setRegistrant(Key.create(persistActiveContact("jd1234"))) .setRegistrant(Key.create(persistActiveContact("jd1234")))
.build()); .build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -285,8 +287,7 @@ public class DomainApplicationInfoFlowTest
AppEngineRule.makeRegistrar1().asBuilder().setClientId("ClientZ").build()); AppEngineRule.makeRegistrar1().asBuilder().setClientId("ClientZ").build());
sessionMetadata.setClientId("ClientZ"); sessionMetadata.setClientId("ClientZ");
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -297,16 +298,14 @@ public class DomainApplicationInfoFlowTest
.setRegistrant(Key.create(persistActiveContact("jd1234"))) .setRegistrant(Key.create(persistActiveContact("jd1234")))
.setPhase(LaunchPhase.SUNRUSH) .setPhase(LaunchPhase.SUNRUSH)
.build()); .build());
thrown.expect(ApplicationDomainNameMismatchException.class); assertThrows(ApplicationDomainNameMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_noApplicationId() throws Exception { public void testFailure_noApplicationId() throws Exception {
setEppInput("domain_info_sunrise_no_application_id.xml"); setEppInput("domain_info_sunrise_no_application_id.xml");
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
thrown.expect(MissingApplicationIdException.class); assertThrows(MissingApplicationIdException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -314,8 +313,7 @@ public class DomainApplicationInfoFlowTest
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST); persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
application = persistResource( application = persistResource(
application.asBuilder().setPhase(LaunchPhase.SUNRISE).build()); application.asBuilder().setPhase(LaunchPhase.SUNRISE).build());
thrown.expect(ApplicationLaunchPhaseMismatchException.class); assertThrows(ApplicationLaunchPhaseMismatchException.class, () -> runFlow());
runFlow();
} }
/** Test that we load contacts and hosts as a batch rather than individually. */ /** Test that we load contacts and hosts as a batch rather than individually. */

View file

@ -29,6 +29,7 @@ import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.JUnitBackports.assertThrows; 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 google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -371,8 +372,7 @@ public class DomainApplicationUpdateFlowTest
setEppInput("domain_update_sunrise_dsdata_add.xml"); setEppInput("domain_update_sunrise_dsdata_add.xml");
persistResource(newApplicationBuilder().setDsData(builder.build()).build()); persistResource(newApplicationBuilder().setDsData(builder.build()).build());
thrown.expect(TooManyDsRecordsException.class); assertThrows(TooManyDsRecordsException.class, () -> runFlow());
runFlow();
} }
private void modifyApplicationToHave13Nameservers() throws Exception { private void modifyApplicationToHave13Nameservers() throws Exception {
@ -395,40 +395,37 @@ public class DomainApplicationUpdateFlowTest
// Modify application to have 13 nameservers. We will then remove one and add one in the test. // Modify application to have 13 nameservers. We will then remove one and add one in the test.
modifyApplicationToHave13Nameservers(); modifyApplicationToHave13Nameservers();
setEppInput("domain_update_sunrise_add_nameserver.xml"); setEppInput("domain_update_sunrise_add_nameserver.xml");
thrown.expect(TooManyNameserversException.class); assertThrows(TooManyNameserversException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_wrongExtension() throws Exception { public void testFailure_wrongExtension() throws Exception {
setEppInput("domain_update_sunrise_wrong_extension.xml"); setEppInput("domain_update_sunrise_wrong_extension.xml");
thrown.expect(UnimplementedExtensionException.class); assertThrows(UnimplementedExtensionException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_applicationDomainNameMismatch() throws Exception { public void testFailure_applicationDomainNameMismatch() throws Exception {
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder().setFullyQualifiedDomainName("something.tld").build()); persistResource(newApplicationBuilder().setFullyQualifiedDomainName("something.tld").build());
thrown.expect(ApplicationDomainNameMismatchException.class); assertThrows(ApplicationDomainNameMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
persistReferencedEntities(); persistReferencedEntities();
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder().setDeletionTime(START_OF_TIME).build()); persistResource(newApplicationBuilder().setDeletionTime(START_OF_TIME).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -437,8 +434,7 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder().setStatusValues( persistResource(newApplicationBuilder().setStatusValues(
ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)).build()); ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)).build());
thrown.expect(ResourceHasClientUpdateProhibitedException.class); assertThrows(ResourceHasClientUpdateProhibitedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -446,16 +442,15 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder().setStatusValues( persistResource(newApplicationBuilder().setStatusValues(
ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED)).build()); ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED)).build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("serverUpdateProhibited"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited");
} }
private void doIllegalApplicationStatusTest(ApplicationStatus status) throws Exception { private void doIllegalApplicationStatusTest(ApplicationStatus status) throws Exception {
persistReferencedEntities(); persistReferencedEntities();
persistResource(newApplicationBuilder().setApplicationStatus(status).build()); persistResource(newApplicationBuilder().setApplicationStatus(status).build());
thrown.expect(ApplicationStatusProhibitsUpdateException.class); assertThrows(ApplicationStatusProhibitsUpdateException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -479,9 +474,9 @@ public class DomainApplicationUpdateFlowTest
persistActiveContact("sh8013"); persistActiveContact("sh8013");
persistActiveContact("mak21"); persistActiveContact("mak21");
persistNewApplication(); persistNewApplication();
thrown.expect(LinkedResourcesDoNotExistException.class); LinkedResourcesDoNotExistException thrown =
thrown.expectMessage("(ns2.example.tld)"); expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(ns2.example.tld)");
} }
@Test @Test
@ -490,9 +485,9 @@ public class DomainApplicationUpdateFlowTest
persistActiveHost("ns2.example.tld"); persistActiveHost("ns2.example.tld");
persistActiveContact("mak21"); persistActiveContact("mak21");
persistNewApplication(); persistNewApplication();
thrown.expect(LinkedResourcesDoNotExistException.class); LinkedResourcesDoNotExistException thrown =
thrown.expectMessage("(sh8013)"); expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(sh8013)");
} }
@Test @Test
@ -505,8 +500,7 @@ public class DomainApplicationUpdateFlowTest
persistResource(reloadDomainApplication().asBuilder().setContacts(ImmutableSet.of( persistResource(reloadDomainApplication().asBuilder().setContacts(ImmutableSet.of(
DesignatedContact.create(Type.TECH, Key.create( DesignatedContact.create(Type.TECH, Key.create(
loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))).build()); loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))).build());
thrown.expect(DuplicateContactForRoleException.class); assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -514,8 +508,7 @@ public class DomainApplicationUpdateFlowTest
setEppInput("domain_update_sunrise_prohibited_status.xml"); setEppInput("domain_update_sunrise_prohibited_status.xml");
persistReferencedEntities(); persistReferencedEntities();
persistNewApplication(); persistNewApplication();
thrown.expect(StatusNotClientSettableException.class); assertThrows(StatusNotClientSettableException.class, () -> runFlow());
runFlow();
} }
@ -536,8 +529,7 @@ public class DomainApplicationUpdateFlowTest
setEppInput("domain_update_sunrise_duplicate_contact.xml"); setEppInput("domain_update_sunrise_duplicate_contact.xml");
persistReferencedEntities(); persistReferencedEntities();
persistNewApplication(); persistNewApplication();
thrown.expect(DuplicateContactForRoleException.class); assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -546,8 +538,7 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities(); persistReferencedEntities();
persistNewApplication(); persistNewApplication();
// We need to test for missing type, but not for invalid - the schema enforces that for us. // We need to test for missing type, but not for invalid - the schema enforces that for us.
thrown.expect(MissingContactTypeException.class); assertThrows(MissingContactTypeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -555,8 +546,7 @@ public class DomainApplicationUpdateFlowTest
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistReferencedEntities(); persistReferencedEntities();
persistApplication(); persistApplication();
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -575,8 +565,7 @@ public class DomainApplicationUpdateFlowTest
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistReferencedEntities(); persistReferencedEntities();
persistApplication(); persistApplication();
thrown.expect(NotAuthorizedForTldException.class); assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -598,8 +587,7 @@ public class DomainApplicationUpdateFlowTest
.setNameservers(ImmutableSet.of(Key.create( .setNameservers(ImmutableSet.of(Key.create(
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc())))) loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
.build()); .build());
thrown.expect(AddRemoveSameValueException.class); assertThrows(AddRemoveSameValueException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -612,8 +600,7 @@ public class DomainApplicationUpdateFlowTest
Key.create( Key.create(
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))))) loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())))))
.build()); .build());
thrown.expect(AddRemoveSameValueException.class); assertThrows(AddRemoveSameValueException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -625,8 +612,7 @@ public class DomainApplicationUpdateFlowTest
DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) DesignatedContact.create(Type.TECH, Key.create(sh8013Contact))))
.build()); .build());
thrown.expect(MissingAdminContactException.class); assertThrows(MissingAdminContactException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -638,8 +624,7 @@ public class DomainApplicationUpdateFlowTest
DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) DesignatedContact.create(Type.TECH, Key.create(sh8013Contact))))
.build()); .build());
thrown.expect(MissingTechnicalContactException.class); assertThrows(MissingTechnicalContactException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -651,8 +636,7 @@ public class DomainApplicationUpdateFlowTest
.setAllowedRegistrantContactIds(ImmutableSet.of("contact1234")) .setAllowedRegistrantContactIds(ImmutableSet.of("contact1234"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(RegistrantNotAllowedException.class); assertThrows(RegistrantNotAllowedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -664,8 +648,7 @@ public class DomainApplicationUpdateFlowTest
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForTldException.class); assertThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -692,8 +675,8 @@ public class DomainApplicationUpdateFlowTest
ImmutableSet.of("ns1.example.tld", "ns2.example.tld")) ImmutableSet.of("ns1.example.tld", "ns2.example.tld"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class); assertThrows(
runFlow(); NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, () -> runFlow());
} }
@Test @Test
@ -746,9 +729,9 @@ public class DomainApplicationUpdateFlowTest
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns3.example.tld")) "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns3.example.tld"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForDomainException.class); NameserversNotAllowedForDomainException thrown =
thrown.expectMessage("ns2.example.tld"); expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns2.example.tld");
} }
@Test @Test
@ -764,8 +747,8 @@ public class DomainApplicationUpdateFlowTest
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns2.example.tld")) "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns2.example.tld"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class); assertThrows(
runFlow(); NameserversNotSpecifiedForNameserverRestrictedDomainException.class, () -> runFlow());
} }
@Test @Test
@ -825,9 +808,9 @@ public class DomainApplicationUpdateFlowTest
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns3.example.tld")) "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns3.example.tld"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForDomainException.class); NameserversNotAllowedForDomainException thrown =
thrown.expectMessage("ns2.example.tld"); expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns2.example.tld");
} }
@Test @Test
@ -845,9 +828,9 @@ public class DomainApplicationUpdateFlowTest
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns2.example.tld")) "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns2.example.tld"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForTldException.class); NameserversNotAllowedForTldException thrown =
thrown.expectMessage("ns2.example.tld"); expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns2.example.tld");
} }
@Test @Test
@ -859,8 +842,7 @@ public class DomainApplicationUpdateFlowTest
"domain_update_sunrise_fee.xml", "domain_update_sunrise_fee.xml",
ImmutableMap.of("DOMAIN", "non-free-update.tld", "AMOUNT", "12.00")); ImmutableMap.of("DOMAIN", "non-free-update.tld", "AMOUNT", "12.00"));
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -274,23 +274,20 @@ public class DomainCheckFlowTest
@Test @Test
public void testFailure_tooManyIds() throws Exception { public void testFailure_tooManyIds() throws Exception {
setEppInput("domain_check_51.xml"); setEppInput("domain_check_51.xml");
thrown.expect(TooManyResourceChecksException.class); assertThrows(TooManyResourceChecksException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_wrongTld() throws Exception { public void testFailure_wrongTld() throws Exception {
setEppInput("domain_check.xml"); setEppInput("domain_check.xml");
thrown.expect(TldDoesNotExistException.class); assertThrows(TldDoesNotExistException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_notAuthorizedForTld() throws Exception { public void testFailure_notAuthorizedForTld() throws Exception {
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class); assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -389,8 +386,7 @@ public class DomainCheckFlowTest
@Test @Test
public void testFailure_predelegation() throws Exception { public void testFailure_predelegation() throws Exception {
createTld("tld", TldState.PREDELEGATION); createTld("tld", TldState.PREDELEGATION);
thrown.expect(BadCommandForRegistryPhaseException.class); assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -677,177 +673,152 @@ public class DomainCheckFlowTest
@Test @Test
public void testFeeExtension_wrongCurrency_v06() throws Exception { public void testFeeExtension_wrongCurrency_v06() throws Exception {
setEppInput("domain_check_fee_euro_v06.xml"); setEppInput("domain_check_fee_euro_v06.xml");
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_wrongCurrency_v11() throws Exception { public void testFeeExtension_wrongCurrency_v11() throws Exception {
setEppInput("domain_check_fee_euro_v11.xml"); setEppInput("domain_check_fee_euro_v11.xml");
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_wrongCurrency_v12() throws Exception { public void testFeeExtension_wrongCurrency_v12() throws Exception {
setEppInput("domain_check_fee_euro_v12.xml"); setEppInput("domain_check_fee_euro_v12.xml");
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_periodNotInYears_v06() throws Exception { public void testFeeExtension_periodNotInYears_v06() throws Exception {
setEppInput("domain_check_fee_bad_period_v06.xml"); setEppInput("domain_check_fee_bad_period_v06.xml");
thrown.expect(BadPeriodUnitException.class); assertThrows(BadPeriodUnitException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_periodNotInYears_v11() throws Exception { public void testFeeExtension_periodNotInYears_v11() throws Exception {
setEppInput("domain_check_fee_bad_period_v11.xml"); setEppInput("domain_check_fee_bad_period_v11.xml");
thrown.expect(BadPeriodUnitException.class); assertThrows(BadPeriodUnitException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_periodNotInYears_v12() throws Exception { public void testFeeExtension_periodNotInYears_v12() throws Exception {
setEppInput("domain_check_fee_bad_period_v12.xml"); setEppInput("domain_check_fee_bad_period_v12.xml");
thrown.expect(BadPeriodUnitException.class); assertThrows(BadPeriodUnitException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_commandWithPhase_v06() throws Exception { public void testFeeExtension_commandWithPhase_v06() throws Exception {
setEppInput("domain_check_fee_command_phase_v06.xml"); setEppInput("domain_check_fee_command_phase_v06.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class); assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_commandWithPhase_v11() throws Exception { public void testFeeExtension_commandWithPhase_v11() throws Exception {
setEppInput("domain_check_fee_command_phase_v11.xml"); setEppInput("domain_check_fee_command_phase_v11.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class); assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_commandWithPhase_v12() throws Exception { public void testFeeExtension_commandWithPhase_v12() throws Exception {
setEppInput("domain_check_fee_command_phase_v12.xml"); setEppInput("domain_check_fee_command_phase_v12.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class); assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_commandSubphase_v06() throws Exception { public void testFeeExtension_commandSubphase_v06() throws Exception {
setEppInput("domain_check_fee_command_subphase_v06.xml"); setEppInput("domain_check_fee_command_subphase_v06.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class); assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_commandSubphase_v11() throws Exception { public void testFeeExtension_commandSubphase_v11() throws Exception {
setEppInput("domain_check_fee_command_subphase_v11.xml"); setEppInput("domain_check_fee_command_subphase_v11.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class); assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_commandSubphase_v12() throws Exception { public void testFeeExtension_commandSubphase_v12() throws Exception {
setEppInput("domain_check_fee_command_subphase_v12.xml"); setEppInput("domain_check_fee_command_subphase_v12.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class); assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
runFlow();
} }
// This test is only relevant for v06, since domain names are not specified in v11 or v12. // This test is only relevant for v06, since domain names are not specified in v11 or v12.
@Test @Test
public void testFeeExtension_feeCheckNotInAvailabilityCheck() throws Exception { public void testFeeExtension_feeCheckNotInAvailabilityCheck() throws Exception {
setEppInput("domain_check_fee_not_in_avail.xml"); setEppInput("domain_check_fee_not_in_avail.xml");
thrown.expect(OnlyCheckedNamesCanBeFeeCheckedException.class); assertThrows(OnlyCheckedNamesCanBeFeeCheckedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_multiyearRestore_v06() throws Exception { public void testFeeExtension_multiyearRestore_v06() throws Exception {
setEppInput("domain_check_fee_multiyear_restore_v06.xml"); setEppInput("domain_check_fee_multiyear_restore_v06.xml");
thrown.expect(RestoresAreAlwaysForOneYearException.class); assertThrows(RestoresAreAlwaysForOneYearException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_multiyearRestore_v11() throws Exception { public void testFeeExtension_multiyearRestore_v11() throws Exception {
setEppInput("domain_check_fee_multiyear_restore_v11.xml"); setEppInput("domain_check_fee_multiyear_restore_v11.xml");
thrown.expect(RestoresAreAlwaysForOneYearException.class); assertThrows(RestoresAreAlwaysForOneYearException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_multiyearRestore_v12() throws Exception { public void testFeeExtension_multiyearRestore_v12() throws Exception {
setEppInput("domain_check_fee_multiyear_restore_v12.xml"); setEppInput("domain_check_fee_multiyear_restore_v12.xml");
thrown.expect(RestoresAreAlwaysForOneYearException.class); assertThrows(RestoresAreAlwaysForOneYearException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_multiyearTransfer_v06() throws Exception { public void testFeeExtension_multiyearTransfer_v06() throws Exception {
setEppInput("domain_check_fee_multiyear_transfer_v06.xml"); setEppInput("domain_check_fee_multiyear_transfer_v06.xml");
thrown.expect(TransfersAreAlwaysForOneYearException.class); assertThrows(TransfersAreAlwaysForOneYearException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_multiyearTransfer_v11() throws Exception { public void testFeeExtension_multiyearTransfer_v11() throws Exception {
setEppInput("domain_check_fee_multiyear_transfer_v11.xml"); setEppInput("domain_check_fee_multiyear_transfer_v11.xml");
thrown.expect(TransfersAreAlwaysForOneYearException.class); assertThrows(TransfersAreAlwaysForOneYearException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_multiyearTransfer_v12() throws Exception { public void testFeeExtension_multiyearTransfer_v12() throws Exception {
setEppInput("domain_check_fee_multiyear_transfer_v12.xml"); setEppInput("domain_check_fee_multiyear_transfer_v12.xml");
thrown.expect(TransfersAreAlwaysForOneYearException.class); assertThrows(TransfersAreAlwaysForOneYearException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_unknownCommand_v06() throws Exception { public void testFeeExtension_unknownCommand_v06() throws Exception {
setEppInput("domain_check_fee_unknown_command_v06.xml"); setEppInput("domain_check_fee_unknown_command_v06.xml");
thrown.expect(UnknownFeeCommandException.class); assertThrows(UnknownFeeCommandException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_unknownCommand_v11() throws Exception { public void testFeeExtension_unknownCommand_v11() throws Exception {
setEppInput("domain_check_fee_unknown_command_v11.xml"); setEppInput("domain_check_fee_unknown_command_v11.xml");
thrown.expect(UnknownFeeCommandException.class); assertThrows(UnknownFeeCommandException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_unknownCommand_v12() throws Exception { public void testFeeExtension_unknownCommand_v12() throws Exception {
setEppInput("domain_check_fee_unknown_command_v12.xml"); setEppInput("domain_check_fee_unknown_command_v12.xml");
thrown.expect(UnknownFeeCommandException.class); assertThrows(UnknownFeeCommandException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_invalidCommand_v06() throws Exception { public void testFeeExtension_invalidCommand_v06() throws Exception {
setEppInput("domain_check_fee_invalid_command_v06.xml"); setEppInput("domain_check_fee_invalid_command_v06.xml");
thrown.expect(UnknownFeeCommandException.class); assertThrows(UnknownFeeCommandException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_invalidCommand_v11() throws Exception { public void testFeeExtension_invalidCommand_v11() throws Exception {
setEppInput("domain_check_fee_invalid_command_v11.xml"); setEppInput("domain_check_fee_invalid_command_v11.xml");
thrown.expect(UnknownFeeCommandException.class); assertThrows(UnknownFeeCommandException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFeeExtension_invalidCommand_v12() throws Exception { public void testFeeExtension_invalidCommand_v12() throws Exception {
setEppInput("domain_check_fee_invalid_command_v12.xml"); setEppInput("domain_check_fee_invalid_command_v12.xml");
thrown.expect(UnknownFeeCommandException.class); assertThrows(UnknownFeeCommandException.class, () -> runFlow());
runFlow();
} }
private void runEapFeeCheckTest(String inputFile, String outputFile) throws Exception { private void runEapFeeCheckTest(String inputFile, String outputFile) throws Exception {

View file

@ -18,6 +18,7 @@ import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -101,23 +102,20 @@ public class DomainClaimsCheckFlowTest
@Test @Test
public void testFailure_TooManyIds() throws Exception { public void testFailure_TooManyIds() throws Exception {
setEppInput("domain_check_claims_51.xml"); setEppInput("domain_check_claims_51.xml");
thrown.expect(TooManyResourceChecksException.class); assertThrows(TooManyResourceChecksException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_tldDoesntExist() throws Exception { public void testFailure_tldDoesntExist() throws Exception {
setEppInput("domain_check_claims_bad_tld.xml"); setEppInput("domain_check_claims_bad_tld.xml");
thrown.expect(TldDoesNotExistException.class); assertThrows(TldDoesNotExistException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_notAuthorizedForTld() throws Exception { public void testFailure_notAuthorizedForTld() throws Exception {
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class); assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -138,8 +136,7 @@ public class DomainClaimsCheckFlowTest
createTld("tld", TldState.PREDELEGATION); createTld("tld", TldState.PREDELEGATION);
persistResource(Registry.get("tld").asBuilder().build()); persistResource(Registry.get("tld").asBuilder().build());
setEppInput("domain_check_claims.xml"); setEppInput("domain_check_claims.xml");
thrown.expect(BadCommandForRegistryPhaseException.class); assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -147,8 +144,7 @@ public class DomainClaimsCheckFlowTest
createTld("tld", TldState.SUNRISE); createTld("tld", TldState.SUNRISE);
persistResource(Registry.get("tld").asBuilder().build()); persistResource(Registry.get("tld").asBuilder().build());
setEppInput("domain_check_claims.xml"); setEppInput("domain_check_claims.xml");
thrown.expect(DomainClaimsCheckNotAllowedInSunrise.class); assertThrows(DomainClaimsCheckNotAllowedInSunrise.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -158,8 +154,7 @@ public class DomainClaimsCheckFlowTest
persistResource( persistResource(
Registry.get("tld2").asBuilder().setClaimsPeriodEnd(clock.nowUtc().minusMillis(1)).build()); Registry.get("tld2").asBuilder().setClaimsPeriodEnd(clock.nowUtc().minusMillis(1)).build());
setEppInput("domain_check_claims_multiple_tlds.xml"); setEppInput("domain_check_claims_multiple_tlds.xml");
thrown.expect(ClaimsPeriodEndedException.class); assertThrows(ClaimsPeriodEndedException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -386,8 +386,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTlds("foo.tld", "tld"); createTlds("foo.tld", "tld");
setEppInput("domain_create_wildcard.xml", ImmutableMap.of("DOMAIN", "foo.tld")); setEppInput("domain_create_wildcard.xml", ImmutableMap.of("DOMAIN", "foo.tld"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(DomainNameExistsAsTldException.class); assertThrows(DomainNameExistsAsTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -395,8 +394,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTlds("foo.tld", "tld"); createTlds("foo.tld", "tld");
setEppInput("domain_create_wildcard.xml", ImmutableMap.of("DOMAIN", "FOO.TLD")); setEppInput("domain_create_wildcard.xml", ImmutableMap.of("DOMAIN", "FOO.TLD"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(BadDomainNameCharacterException.class); assertThrows(BadDomainNameCharacterException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -536,72 +534,63 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_refundableFee_v06() throws Exception { public void testFailure_refundableFee_v06() throws Exception {
setEppInput("domain_create_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.6")); setEppInput("domain_create_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_refundableFee_v11() throws Exception { public void testFailure_refundableFee_v11() throws Exception {
setEppInput("domain_create_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.11")); setEppInput("domain_create_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_refundableFee_v12() throws Exception { public void testFailure_refundableFee_v12() throws Exception {
setEppInput("domain_create_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.12")); setEppInput("domain_create_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_gracePeriodFee_v06() throws Exception { public void testFailure_gracePeriodFee_v06() throws Exception {
setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.6")); setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_gracePeriodFee_v11() throws Exception { public void testFailure_gracePeriodFee_v11() throws Exception {
setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.11")); setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_gracePeriodFee_v12() throws Exception { public void testFailure_gracePeriodFee_v12() throws Exception {
setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.12")); setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_appliedFee_v06() throws Exception { public void testFailure_appliedFee_v06() throws Exception {
setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.6")); setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_appliedFee_v11() throws Exception { public void testFailure_appliedFee_v11() throws Exception {
setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.11")); setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_appliedFee_v12() throws Exception { public void testFailure_appliedFee_v12() throws Exception {
setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.12")); setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -621,8 +610,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_metadataNotFromTool() throws Exception { public void testFailure_metadataNotFromTool() throws Exception {
setEppInput("domain_create_metadata.xml"); setEppInput("domain_create_metadata.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(OnlyToolCanPassMetadataException.class); assertThrows(OnlyToolCanPassMetadataException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -649,9 +637,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1))) .setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1)))
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(InvalidLrpTokenException.class); InvalidLrpTokenException thrown = expectThrows(InvalidLrpTokenException.class, () -> runFlow());
thrown.expectMessage("Invalid limited registration period token"); assertThat(thrown).hasMessageThat().contains("Invalid limited registration period token");
runFlow();
} }
@Test @Test
@ -750,8 +737,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_periodInMonths() throws Exception { public void testFailure_periodInMonths() throws Exception {
setEppInput("domain_create_months.xml"); setEppInput("domain_create_months.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(BadPeriodUnitException.class); assertThrows(BadPeriodUnitException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -783,8 +769,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistClaimsList(ImmutableMap.of("example", CLAIMS_KEY)); persistClaimsList(ImmutableMap.of("example", CLAIMS_KEY));
setEppInput("domain_create.xml"); setEppInput("domain_create.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(MissingClaimsNoticeException.class); assertThrows(MissingClaimsNoticeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -792,8 +777,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
setEppInput("domain_create_claim_notice.xml"); setEppInput("domain_create_claim_notice.xml");
persistClaimsList(ImmutableMap.of()); persistClaimsList(ImmutableMap.of());
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnexpectedClaimsNoticeException.class); assertThrows(UnexpectedClaimsNoticeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -804,40 +788,35 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource(Registry.get("tld").asBuilder() persistResource(Registry.get("tld").asBuilder()
.setClaimsPeriodEnd(clock.nowUtc()) .setClaimsPeriodEnd(clock.nowUtc())
.build()); .build());
thrown.expect(ClaimsPeriodEndedException.class); assertThrows(ClaimsPeriodEndedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_tooManyNameservers() throws Exception { public void testFailure_tooManyNameservers() throws Exception {
setEppInput("domain_create_14_nameservers.xml"); setEppInput("domain_create_14_nameservers.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(TooManyNameserversException.class); assertThrows(TooManyNameserversException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_secDnsMaxSigLife() throws Exception { public void testFailure_secDnsMaxSigLife() throws Exception {
setEppInput("domain_create_dsdata.xml"); setEppInput("domain_create_dsdata.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(MaxSigLifeNotSupportedException.class); assertThrows(MaxSigLifeNotSupportedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_secDnsTooManyDsRecords() throws Exception { public void testFailure_secDnsTooManyDsRecords() throws Exception {
setEppInput("domain_create_dsdata_9_records.xml"); setEppInput("domain_create_dsdata_9_records.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(TooManyDsRecordsException.class); assertThrows(TooManyDsRecordsException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_wrongExtension() throws Exception { public void testFailure_wrongExtension() throws Exception {
setEppInput("domain_create_wrong_extension.xml"); setEppInput("domain_create_wrong_extension.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnimplementedExtensionException.class); assertThrows(UnimplementedExtensionException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -846,8 +825,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource( persistResource(
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -856,8 +834,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource( persistResource(
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -866,8 +843,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource( persistResource(
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build()); Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -882,8 +858,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setServerStatusChangeBillingCost(Money.of(EUR, 19)) .setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -898,8 +873,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setServerStatusChangeBillingCost(Money.of(EUR, 19)) .setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -914,8 +888,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setServerStatusChangeBillingCost(Money.of(EUR, 19)) .setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -939,16 +912,14 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_reserved() throws Exception { public void testFailure_reserved() throws Exception {
setEppInput("domain_create_reserved.xml"); setEppInput("domain_create_reserved.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(DomainReservedException.class); assertThrows(DomainReservedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_anchorTenantViaAuthCode_wrongAuthCode() throws Exception { public void testFailure_anchorTenantViaAuthCode_wrongAuthCode() throws Exception {
setEppInput("domain_create_anchor_wrong_authcode.xml"); setEppInput("domain_create_anchor_wrong_authcode.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(DomainReservedException.class); assertThrows(DomainReservedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1045,9 +1016,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistActiveHost("ns1.example.net"); persistActiveHost("ns1.example.net");
persistActiveContact("jd1234"); persistActiveContact("jd1234");
persistActiveContact("sh8013"); persistActiveContact("sh8013");
thrown.expect(LinkedResourcesDoNotExistException.class); LinkedResourcesDoNotExistException thrown =
thrown.expectMessage("(ns2.example.net)"); expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(ns2.example.net)");
} }
@Test @Test
@ -1059,9 +1030,10 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.addStatusValue(StatusValue.PENDING_DELETE) .addStatusValue(StatusValue.PENDING_DELETE)
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(LinkedResourceInPendingDeleteProhibitsOperationException.class); LinkedResourceInPendingDeleteProhibitsOperationException thrown =
thrown.expectMessage("ns2.example.net"); expectThrows(
runFlow(); LinkedResourceInPendingDeleteProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns2.example.net");
} }
@Test @Test
@ -1069,8 +1041,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistContactsAndHosts(); persistContactsAndHosts();
persistActiveDomainApplication(getUniqueIdFromCommand()); persistActiveDomainApplication(getUniqueIdFromCommand());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(DomainHasOpenApplicationsException.class); assertThrows(DomainHasOpenApplicationsException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1095,9 +1066,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistActiveHost("ns1.example.net"); persistActiveHost("ns1.example.net");
persistActiveHost("ns2.example.net"); persistActiveHost("ns2.example.net");
persistActiveContact("jd1234"); persistActiveContact("jd1234");
thrown.expect(LinkedResourcesDoNotExistException.class); LinkedResourcesDoNotExistException thrown =
thrown.expectMessage("(sh8013)"); expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(sh8013)");
} }
@Test @Test
@ -1109,57 +1080,52 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.addStatusValue(StatusValue.PENDING_DELETE) .addStatusValue(StatusValue.PENDING_DELETE)
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(LinkedResourceInPendingDeleteProhibitsOperationException.class); LinkedResourceInPendingDeleteProhibitsOperationException thrown =
thrown.expectMessage("jd1234"); expectThrows(
runFlow(); LinkedResourceInPendingDeleteProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("jd1234");
} }
@Test @Test
public void testFailure_wrongTld() throws Exception { public void testFailure_wrongTld() throws Exception {
persistContactsAndHosts("net"); persistContactsAndHosts("net");
deleteTld("tld"); deleteTld("tld");
thrown.expect(TldDoesNotExistException.class); assertThrows(TldDoesNotExistException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_predelegation() throws Exception { public void testFailure_predelegation() throws Exception {
createTld("tld", TldState.PREDELEGATION); createTld("tld", TldState.PREDELEGATION);
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_sunrise() throws Exception { public void testFailure_sunrise() throws Exception {
createTld("tld", TldState.SUNRISE); createTld("tld", TldState.SUNRISE);
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_sunrush() throws Exception { public void testFailure_sunrush() throws Exception {
createTld("tld", TldState.SUNRUSH); createTld("tld", TldState.SUNRUSH);
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_landrush() throws Exception { public void testFailure_landrush() throws Exception {
createTld("tld", TldState.LANDRUSH); createTld("tld", TldState.LANDRUSH);
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_quietPeriod() throws Exception { public void testFailure_quietPeriod() throws Exception {
createTld("tld", TldState.QUIET_PERIOD); createTld("tld", TldState.QUIET_PERIOD);
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1232,8 +1198,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_duplicateContact() throws Exception { public void testFailure_duplicateContact() throws Exception {
setEppInput("domain_create_duplicate_contact.xml"); setEppInput("domain_create_duplicate_contact.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(DuplicateContactForRoleException.class); assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1241,40 +1206,35 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
// We need to test for missing type, but not for invalid - the schema enforces that for us. // We need to test for missing type, but not for invalid - the schema enforces that for us.
setEppInput("domain_create_missing_contact_type.xml"); setEppInput("domain_create_missing_contact_type.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(MissingContactTypeException.class); assertThrows(MissingContactTypeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_missingRegistrant() throws Exception { public void testFailure_missingRegistrant() throws Exception {
setEppInput("domain_create_missing_registrant.xml"); setEppInput("domain_create_missing_registrant.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(MissingRegistrantException.class); assertThrows(MissingRegistrantException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_missingAdmin() throws Exception { public void testFailure_missingAdmin() throws Exception {
setEppInput("domain_create_missing_admin.xml"); setEppInput("domain_create_missing_admin.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(MissingAdminContactException.class); assertThrows(MissingAdminContactException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_missingTech() throws Exception { public void testFailure_missingTech() throws Exception {
setEppInput("domain_create_missing_tech.xml"); setEppInput("domain_create_missing_tech.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(MissingTechnicalContactException.class); assertThrows(MissingTechnicalContactException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_missingNonRegistrantContacts() throws Exception { public void testFailure_missingNonRegistrantContacts() throws Exception {
setEppInput("domain_create_missing_non_registrant_contacts.xml"); setEppInput("domain_create_missing_non_registrant_contacts.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(MissingAdminContactException.class); assertThrows(MissingAdminContactException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1282,8 +1242,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("xn--q9jyb4c"); createTld("xn--q9jyb4c");
setEppInput("domain_create_bad_idn_minna.xml"); setEppInput("domain_create_bad_idn_minna.xml");
persistContactsAndHosts("net"); persistContactsAndHosts("net");
thrown.expect(InvalidIdnDomainLabelException.class); assertThrows(InvalidIdnDomainLabelException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1291,16 +1250,14 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
setEppInput("domain_create_bad_validator_id.xml"); setEppInput("domain_create_bad_validator_id.xml");
persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY)); persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(InvalidTrademarkValidatorException.class); assertThrows(InvalidTrademarkValidatorException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_codeMark() throws Exception { public void testFailure_codeMark() throws Exception {
setEppInput("domain_create_code_with_mark.xml"); setEppInput("domain_create_code_with_mark.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UnsupportedMarkTypeException.class); assertThrows(UnsupportedMarkTypeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1308,8 +1265,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("tld", TldState.SUNRISE); createTld("tld", TldState.SUNRISE);
setEppInput("domain_create_signed_mark.xml"); setEppInput("domain_create_signed_mark.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1317,8 +1273,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
clock.setTo(DateTime.parse("2010-08-17T09:00:00.0Z")); clock.setTo(DateTime.parse("2010-08-17T09:00:00.0Z"));
setEppInput("domain_create_claim_notice.xml"); setEppInput("domain_create_claim_notice.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(ExpiredClaimException.class); assertThrows(ExpiredClaimException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1326,8 +1281,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
clock.setTo(DateTime.parse("2009-09-16T09:00:00.0Z")); clock.setTo(DateTime.parse("2009-09-16T09:00:00.0Z"));
setEppInput("domain_create_claim_notice.xml"); setEppInput("domain_create_claim_notice.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(AcceptedTooLongAgoException.class); assertThrows(AcceptedTooLongAgoException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1335,8 +1289,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z")); clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z"));
setEppInput("domain_create_malformed_claim_notice1.xml"); setEppInput("domain_create_malformed_claim_notice1.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(MalformedTcnIdException.class); assertThrows(MalformedTcnIdException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1344,8 +1297,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z")); clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z"));
setEppInput("domain_create_malformed_claim_notice2.xml"); setEppInput("domain_create_malformed_claim_notice2.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(MalformedTcnIdException.class); assertThrows(MalformedTcnIdException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1353,8 +1305,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z")); clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z"));
setEppInput("domain_create_bad_checksum_claim_notice.xml"); setEppInput("domain_create_bad_checksum_claim_notice.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(InvalidTcnIdChecksumException.class); assertThrows(InvalidTcnIdChecksumException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1367,8 +1318,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource(loadRegistrar("TheRegistrar").asBuilder() persistResource(loadRegistrar("TheRegistrar").asBuilder()
.setBlockPremiumNames(true) .setBlockPremiumNames(true)
.build()); .build());
thrown.expect(PremiumNameBlockedException.class); assertThrows(PremiumNameBlockedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1376,8 +1326,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("example"); createTld("example");
setEppInput("domain_create_premium.xml"); setEppInput("domain_create_premium.xml");
persistContactsAndHosts("net"); persistContactsAndHosts("net");
thrown.expect(FeesRequiredForPremiumNameException.class); assertThrows(FeesRequiredForPremiumNameException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1388,8 +1337,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("net"); createTld("net");
setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.6")); setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UndeclaredServiceExtensionException.class); assertThrows(UndeclaredServiceExtensionException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1400,8 +1348,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("net"); createTld("net");
setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11")); setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UndeclaredServiceExtensionException.class); assertThrows(UndeclaredServiceExtensionException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1412,32 +1359,28 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("net"); createTld("net");
setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.12")); setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(UndeclaredServiceExtensionException.class); assertThrows(UndeclaredServiceExtensionException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v06() throws Exception { public void testFailure_feeGivenInWrongScale_v06() throws Exception {
setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.6")); setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception { public void testFailure_feeGivenInWrongScale_v11() throws Exception {
setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.11")); setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception { public void testFailure_feeGivenInWrongScale_v12() throws Exception {
setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.12")); setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1450,8 +1393,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.asBuilder() .asBuilder()
.setState(State.SUSPENDED) .setState(State.SUSPENDED)
.build()); .build());
thrown.expect(RegistrarMustBeActiveToCreateDomainsException.class); assertThrows(RegistrarMustBeActiveToCreateDomainsException.class, () -> runFlow());
runFlow();
} }
private void doFailingDomainNameTest( private void doFailingDomainNameTest(
@ -1534,8 +1476,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("tld", TldState.SUNRISE); createTld("tld", TldState.SUNRISE);
setEppInput("domain_create_registration_sunrise.xml"); setEppInput("domain_create_registration_sunrise.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1586,8 +1527,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("tld", TldState.SUNRUSH); createTld("tld", TldState.SUNRUSH);
setEppInput("domain_create_registration_sunrush.xml"); setEppInput("domain_create_registration_sunrush.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1599,8 +1539,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setAllowedTlds(ImmutableSet.of("irrelevant")) .setAllowedTlds(ImmutableSet.of("irrelevant"))
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NotAuthorizedForTldException.class); assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1651,8 +1590,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("tld", TldState.LANDRUSH); createTld("tld", TldState.LANDRUSH);
setEppInput("domain_create_registration_landrush.xml"); setEppInput("domain_create_registration_landrush.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class); assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1705,9 +1643,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource(Registry.get("tld").asBuilder() persistResource(Registry.get("tld").asBuilder()
.setAllowedRegistrantContactIds(ImmutableSet.of("someone")) .setAllowedRegistrantContactIds(ImmutableSet.of("someone"))
.build()); .build());
thrown.expect(RegistrantNotAllowedException.class); RegistrantNotAllowedException thrown =
thrown.expectMessage("jd1234"); expectThrows(RegistrantNotAllowedException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("jd1234");
} }
@Test @Test
@ -1716,9 +1654,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource(Registry.get("tld").asBuilder() persistResource(Registry.get("tld").asBuilder()
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net"))
.build()); .build());
thrown.expect(NameserversNotAllowedForTldException.class); NameserversNotAllowedForTldException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -1728,8 +1666,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("somethingelse.example.net")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("somethingelse.example.net"))
.build()); .build());
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class); assertThrows(
runFlow(); NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, () -> runFlow());
} }
@Test @Test
@ -1770,8 +1708,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
"example,NAMESERVER_RESTRICTED," "example,NAMESERVER_RESTRICTED,"
+ "ns1.example.net:ns2.example.net:ns3.example.net")) + "ns1.example.net:ns2.example.net:ns3.example.net"))
.build()); .build());
thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class); assertThrows(
runFlow(); NameserversNotSpecifiedForNameserverRestrictedDomainException.class, () -> runFlow());
} }
@Test @Test
@ -1784,9 +1722,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistReservedList( persistReservedList(
"reserved", "example,NAMESERVER_RESTRICTED,ns2.example.net:ns3.example.net")) "reserved", "example,NAMESERVER_RESTRICTED,ns2.example.net:ns3.example.net"))
.build()); .build());
thrown.expect(NameserversNotAllowedForDomainException.class); NameserversNotAllowedForDomainException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -1800,9 +1738,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistReservedList( persistReservedList(
"reserved", "lol,NAMESERVER_RESTRICTED,ns1.example.net:ns2.example.net")) "reserved", "lol,NAMESERVER_RESTRICTED,ns1.example.net:ns2.example.net"))
.build()); .build());
thrown.expect(DomainNotAllowedForTldWithCreateRestrictionException.class); DomainNotAllowedForTldWithCreateRestrictionException thrown =
thrown.expectMessage("example.tld"); expectThrows(DomainNotAllowedForTldWithCreateRestrictionException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("example.tld");
} }
@Test @Test
@ -1850,9 +1788,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
"example,NAMESERVER_RESTRICTED," "example,NAMESERVER_RESTRICTED,"
+ "ns1.example.net:ns2.example.net:ns3.example.net")) + "ns1.example.net:ns2.example.net:ns3.example.net"))
.build()); .build());
thrown.expect(NameserversNotAllowedForTldException.class); NameserversNotAllowedForTldException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -1869,9 +1807,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
"example,NAMESERVER_RESTRICTED," "example,NAMESERVER_RESTRICTED,"
+ "ns2.example.net:ns3.example.net:ns4.example.net")) + "ns2.example.net:ns3.example.net:ns4.example.net"))
.build()); .build());
thrown.expect(NameserversNotAllowedForDomainException.class); NameserversNotAllowedForDomainException thrown =
thrown.expectMessage("ns1.example.net"); expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns1.example.net");
} }
@Test @Test
@ -1890,9 +1828,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
"lol,NAMESERVER_RESTRICTED," "lol,NAMESERVER_RESTRICTED,"
+ "ns1.example.net:ns2.example.net:ns3.example.net")) + "ns1.example.net:ns2.example.net:ns3.example.net"))
.build()); .build());
thrown.expect(DomainNotAllowedForTldWithCreateRestrictionException.class); DomainNotAllowedForTldWithCreateRestrictionException thrown =
thrown.expectMessage("example.tld"); expectThrows(DomainNotAllowedForTldWithCreateRestrictionException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("example.tld");
} }
@Test @Test
@ -2020,8 +1958,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_max10Years() throws Exception { public void testFailure_max10Years() throws Exception {
setEppInput("domain_create_11_years.xml"); setEppInput("domain_create_11_years.xml");
persistContactsAndHosts(); persistContactsAndHosts();
thrown.expect(ExceedsMaxRegistrationYearsException.class); assertThrows(ExceedsMaxRegistrationYearsException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -42,6 +42,8 @@ import static google.registry.testing.DatastoreHelper.persistDeletedDomain;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -636,8 +638,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
public void testFailure_predelegation() throws Exception { public void testFailure_predelegation() throws Exception {
createTld("tld", TldState.PREDELEGATION); createTld("tld", TldState.PREDELEGATION);
setUpSuccessfulTest(); setUpSuccessfulTest();
thrown.expect(BadCommandForRegistryPhaseException.class); assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -651,17 +652,17 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -674,16 +675,14 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
domain = persistResource(domain.asBuilder() domain = persistResource(domain.asBuilder()
.addSubordinateHost(subordinateHost.getFullyQualifiedHostName()) .addSubordinateHost(subordinateHost.getFullyQualifiedHostName())
.build()); .build());
thrown.expect(DomainToDeleteHasHostsException.class); assertThrows(DomainToDeleteHasHostsException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_unauthorizedClient() throws Exception { public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistActiveDomain(getUniqueIdFromCommand()); persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -700,8 +699,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
setUpSuccessfulTest(); setUpSuccessfulTest();
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class); assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -719,9 +717,9 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder() persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.addStatusValue(StatusValue.CLIENT_DELETE_PROHIBITED) .addStatusValue(StatusValue.CLIENT_DELETE_PROHIBITED)
.build()); .build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("clientDeleteProhibited"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("clientDeleteProhibited");
} }
@Test @Test
@ -729,9 +727,9 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder() persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.addStatusValue(StatusValue.SERVER_DELETE_PROHIBITED) .addStatusValue(StatusValue.SERVER_DELETE_PROHIBITED)
.build()); .build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("serverDeleteProhibited"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("serverDeleteProhibited");
} }
@Test @Test
@ -739,9 +737,9 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder() persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.addStatusValue(StatusValue.PENDING_DELETE) .addStatusValue(StatusValue.PENDING_DELETE)
.build()); .build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("pendingDelete"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("pendingDelete");
} }
@Test @Test
@ -764,8 +762,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
public void testFailure_metadataNotFromTool() throws Exception { public void testFailure_metadataNotFromTool() throws Exception {
setEppInput("domain_delete_metadata.xml"); setEppInput("domain_delete_metadata.xml");
persistResource(newDomainResource(getUniqueIdFromCommand())); persistResource(newDomainResource(getUniqueIdFromCommand()));
thrown.expect(OnlyToolCanPassMetadataException.class); assertThrows(OnlyToolCanPassMetadataException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -23,6 +23,8 @@ import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -373,9 +375,9 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -383,9 +385,9 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
persistResource(newDomainResource("example.tld").asBuilder() persistResource(newDomainResource("example.tld").asBuilder()
.setDeletionTime(clock.nowUtc().minusDays(1)) .setDeletionTime(clock.nowUtc().minusDays(1))
.build()); .build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -397,8 +399,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
.build()); .build());
sessionMetadata.setClientId("ClientZ"); sessionMetadata.setClientId("ClientZ");
setEppInput("domain_info_with_auth.xml"); setEppInput("domain_info_with_auth.xml");
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -409,8 +410,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("diffpw"))) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("diffpw")))
.build()); .build());
setEppInput("domain_info_with_auth.xml"); setEppInput("domain_info_with_auth.xml");
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -425,8 +425,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml"); setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our registrant. // Replace the ROID in the xml file with the one for our registrant.
eppLoader.replaceAll("JD1234-REP", registrant.getRepoId()); eppLoader.replaceAll("JD1234-REP", registrant.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -440,8 +439,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml"); setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our registrant. // Replace the ROID in the xml file with the one for our registrant.
eppLoader.replaceAll("JD1234-REP", registrant.getRepoId()); eppLoader.replaceAll("JD1234-REP", registrant.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -456,8 +454,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml"); setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our contact. // Replace the ROID in the xml file with the one for our contact.
eppLoader.replaceAll("JD1234-REP", contact.getRepoId()); eppLoader.replaceAll("JD1234-REP", contact.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -471,8 +468,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml"); setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our contact. // Replace the ROID in the xml file with the one for our contact.
eppLoader.replaceAll("JD1234-REP", contact.getRepoId()); eppLoader.replaceAll("JD1234-REP", contact.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -483,8 +479,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml"); setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our unrelated contact. // Replace the ROID in the xml file with the one for our unrelated contact.
eppLoader.replaceAll("JD1234-REP", unrelatedContact.getRepoId()); eppLoader.replaceAll("JD1234-REP", unrelatedContact.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -494,8 +489,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml"); setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our unrelated contact. // Replace the ROID in the xml file with the one for our unrelated contact.
eppLoader.replaceAll("JD1234-REP", unrelatedContact.getRepoId()); eppLoader.replaceAll("JD1234-REP", unrelatedContact.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
runFlow();
} }
/** /**
@ -574,8 +568,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
public void testFeeExtension_wrongCurrency() throws Exception { public void testFeeExtension_wrongCurrency() throws Exception {
setEppInput("domain_info_fee_create_euro.xml"); setEppInput("domain_info_fee_create_euro.xml");
persistTestEntities(false); persistTestEntities(false);
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
/** Test requesting a period that isn't in years. */ /** Test requesting a period that isn't in years. */
@ -583,8 +576,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
public void testFeeExtension_periodNotInYears() throws Exception { public void testFeeExtension_periodNotInYears() throws Exception {
setEppInput("domain_info_fee_bad_period.xml"); setEppInput("domain_info_fee_bad_period.xml");
persistTestEntities(false); persistTestEntities(false);
thrown.expect(BadPeriodUnitException.class); assertThrows(BadPeriodUnitException.class, () -> runFlow());
runFlow();
} }
/** Test a command that specifies a phase. */ /** Test a command that specifies a phase. */
@ -592,8 +584,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
public void testFeeExtension_commandPhase() throws Exception { public void testFeeExtension_commandPhase() throws Exception {
setEppInput("domain_info_fee_command_phase.xml"); setEppInput("domain_info_fee_command_phase.xml");
persistTestEntities(false); persistTestEntities(false);
thrown.expect(FeeChecksDontSupportPhasesException.class); assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
runFlow();
} }
/** Test a command that specifies a subphase. */ /** Test a command that specifies a subphase. */
@ -601,8 +592,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
public void testFeeExtension_commandSubphase() throws Exception { public void testFeeExtension_commandSubphase() throws Exception {
setEppInput("domain_info_fee_command_subphase.xml"); setEppInput("domain_info_fee_command_subphase.xml");
persistTestEntities(false); persistTestEntities(false);
thrown.expect(FeeChecksDontSupportPhasesException.class); assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
runFlow();
} }
/** Test a restore for more than one year. */ /** Test a restore for more than one year. */
@ -610,8 +600,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
public void testFeeExtension_multiyearRestore() throws Exception { public void testFeeExtension_multiyearRestore() throws Exception {
setEppInput("domain_info_fee_multiyear_restore.xml"); setEppInput("domain_info_fee_multiyear_restore.xml");
persistTestEntities(false); persistTestEntities(false);
thrown.expect(RestoresAreAlwaysForOneYearException.class); assertThrows(RestoresAreAlwaysForOneYearException.class, () -> runFlow());
runFlow();
} }
/** Test a transfer for more than one year. */ /** Test a transfer for more than one year. */
@ -619,8 +608,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
public void testFeeExtension_multiyearTransfer() throws Exception { public void testFeeExtension_multiyearTransfer() throws Exception {
setEppInput("domain_info_fee_multiyear_transfer.xml"); setEppInput("domain_info_fee_multiyear_transfer.xml");
persistTestEntities(false); persistTestEntities(false);
thrown.expect(TransfersAreAlwaysForOneYearException.class); assertThrows(TransfersAreAlwaysForOneYearException.class, () -> runFlow());
runFlow();
} }
/** Test that we load contacts and hosts as a batch rather than individually. */ /** Test that we load contacts and hosts as a batch rather than individually. */

View file

@ -27,6 +27,8 @@ import static google.registry.testing.DatastoreHelper.persistDeletedDomain;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.EUR; import static org.joda.money.CurrencyUnit.EUR;
@ -291,72 +293,63 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
public void testFailure_refundableFee_v06() throws Exception { public void testFailure_refundableFee_v06() throws Exception {
setEppInput("domain_renew_fee_refundable.xml", FEE_06_MAP); setEppInput("domain_renew_fee_refundable.xml", FEE_06_MAP);
persistDomain(); persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_refundableFee_v11() throws Exception { public void testFailure_refundableFee_v11() throws Exception {
setEppInput("domain_renew_fee_refundable.xml", FEE_11_MAP); setEppInput("domain_renew_fee_refundable.xml", FEE_11_MAP);
persistDomain(); persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_refundableFee_v12() throws Exception { public void testFailure_refundableFee_v12() throws Exception {
setEppInput("domain_renew_fee_refundable.xml", FEE_12_MAP); setEppInput("domain_renew_fee_refundable.xml", FEE_12_MAP);
persistDomain(); persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_gracePeriodFee_v06() throws Exception { public void testFailure_gracePeriodFee_v06() throws Exception {
setEppInput("domain_renew_fee_grace_period.xml", FEE_06_MAP); setEppInput("domain_renew_fee_grace_period.xml", FEE_06_MAP);
persistDomain(); persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_gracePeriodFee_v11() throws Exception { public void testFailure_gracePeriodFee_v11() throws Exception {
setEppInput("domain_renew_fee_grace_period.xml", FEE_11_MAP); setEppInput("domain_renew_fee_grace_period.xml", FEE_11_MAP);
persistDomain(); persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_gracePeriodFee_v12() throws Exception { public void testFailure_gracePeriodFee_v12() throws Exception {
setEppInput("domain_renew_fee_grace_period.xml", FEE_12_MAP); setEppInput("domain_renew_fee_grace_period.xml", FEE_12_MAP);
persistDomain(); persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_appliedFee_v06() throws Exception { public void testFailure_appliedFee_v06() throws Exception {
setEppInput("domain_renew_fee_applied.xml", FEE_06_MAP); setEppInput("domain_renew_fee_applied.xml", FEE_06_MAP);
persistDomain(); persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_appliedFee_v11() throws Exception { public void testFailure_appliedFee_v11() throws Exception {
setEppInput("domain_renew_fee_applied.xml", FEE_11_MAP); setEppInput("domain_renew_fee_applied.xml", FEE_11_MAP);
persistDomain(); persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_appliedFee_v12() throws Exception { public void testFailure_appliedFee_v12() throws Exception {
setEppInput("domain_renew_fee_applied.xml", FEE_12_MAP); setEppInput("domain_renew_fee_applied.xml", FEE_12_MAP);
persistDomain(); persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -410,33 +403,33 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_clientRenewProhibited() throws Exception { public void testFailure_clientRenewProhibited() throws Exception {
persistDomain(StatusValue.CLIENT_RENEW_PROHIBITED); persistDomain(StatusValue.CLIENT_RENEW_PROHIBITED);
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("clientRenewProhibited"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("clientRenewProhibited");
} }
@Test @Test
public void testFailure_serverRenewProhibited() throws Exception { public void testFailure_serverRenewProhibited() throws Exception {
persistDomain(StatusValue.SERVER_RENEW_PROHIBITED); persistDomain(StatusValue.SERVER_RENEW_PROHIBITED);
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("serverRenewProhibited"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("serverRenewProhibited");
} }
@Test @Test
@ -446,9 +439,9 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setDeletionTime(clock.nowUtc().plusDays(1)) .setDeletionTime(clock.nowUtc().plusDays(1))
.addStatusValue(StatusValue.PENDING_DELETE) .addStatusValue(StatusValue.PENDING_DELETE)
.build()); .build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("pendingDelete"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("pendingDelete");
} }
@Test @Test
@ -460,8 +453,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20))) .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build()); .build());
persistDomain(); persistDomain();
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -473,8 +465,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20))) .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build()); .build());
persistDomain(); persistDomain();
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -486,8 +477,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20))) .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build()); .build());
persistDomain(); persistDomain();
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -504,8 +494,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19)) .setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build()); .build());
persistDomain(); persistDomain();
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -522,8 +511,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19)) .setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build()); .build());
persistDomain(); persistDomain();
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -540,32 +528,28 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19)) .setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build()); .build());
persistDomain(); persistDomain();
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v06() throws Exception { public void testFailure_feeGivenInWrongScale_v06() throws Exception {
setEppInput("domain_renew_fee_bad_scale.xml", FEE_06_MAP); setEppInput("domain_renew_fee_bad_scale.xml", FEE_06_MAP);
persistDomain(); persistDomain();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception { public void testFailure_feeGivenInWrongScale_v11() throws Exception {
setEppInput("domain_renew_fee_bad_scale.xml", FEE_11_MAP); setEppInput("domain_renew_fee_bad_scale.xml", FEE_11_MAP);
persistDomain(); persistDomain();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception { public void testFailure_feeGivenInWrongScale_v12() throws Exception {
setEppInput("domain_renew_fee_bad_scale.xml", FEE_12_MAP); setEppInput("domain_renew_fee_bad_scale.xml", FEE_12_MAP);
persistDomain(); persistDomain();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -575,25 +559,23 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.asBuilder() .asBuilder()
.setRegistrationExpirationTime(DateTime.parse("2001-09-08T22:00:00.0Z")) .setRegistrationExpirationTime(DateTime.parse("2001-09-08T22:00:00.0Z"))
.build()); .build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("pendingTransfer"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("pendingTransfer");
} }
@Test @Test
public void testFailure_periodInMonths() throws Exception { public void testFailure_periodInMonths() throws Exception {
setEppInput("domain_renew_months.xml"); setEppInput("domain_renew_months.xml");
persistDomain(); persistDomain();
thrown.expect(BadPeriodUnitException.class); assertThrows(BadPeriodUnitException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_max10Years() throws Exception { public void testFailure_max10Years() throws Exception {
setEppInput("domain_renew_11_years.xml"); setEppInput("domain_renew_11_years.xml");
persistDomain(); persistDomain();
thrown.expect(ExceedsMaxRegistrationYearsException.class); assertThrows(ExceedsMaxRegistrationYearsException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -603,16 +585,14 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
persistResource(reloadResourceByForeignKey().asBuilder() persistResource(reloadResourceByForeignKey().asBuilder()
.setRegistrationExpirationTime(DateTime.parse("2000-04-04T22:00:00.0Z")) .setRegistrationExpirationTime(DateTime.parse("2000-04-04T22:00:00.0Z"))
.build()); .build());
thrown.expect(IncorrectCurrentExpirationDateException.class); assertThrows(IncorrectCurrentExpirationDateException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_unauthorizedClient() throws Exception { public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistActiveDomain(getUniqueIdFromCommand()); persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -628,8 +608,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistDomain(); persistDomain();
thrown.expect(NotAuthorizedForTldException.class); assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -647,8 +626,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
persistResource(Registry.get("example").asBuilder().setPremiumPriceAckRequired(true).build()); persistResource(Registry.get("example").asBuilder().setPremiumPriceAckRequired(true).build());
setEppInput("domain_renew_premium.xml"); setEppInput("domain_renew_premium.xml");
persistDomain(); persistDomain();
thrown.expect(FeesRequiredForPremiumNameException.class); assertThrows(FeesRequiredForPremiumNameException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -27,6 +27,8 @@ import static google.registry.testing.DatastoreHelper.persistDeletedDomain;
import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -232,72 +234,63 @@ public class DomainRestoreRequestFlowTest extends
public void testFailure_refundableFee_v06() throws Exception { public void testFailure_refundableFee_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_06_MAP); setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_06_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_refundableFee_v11() throws Exception { public void testFailure_refundableFee_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_11_MAP); setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_11_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_refundableFee_v12() throws Exception { public void testFailure_refundableFee_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_12_MAP); setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_12_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_gracePeriodFee_v06() throws Exception { public void testFailure_gracePeriodFee_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_06_MAP); setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_06_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_gracePeriodFee_v11() throws Exception { public void testFailure_gracePeriodFee_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_11_MAP); setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_11_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_gracePeriodFee_v12() throws Exception { public void testFailure_gracePeriodFee_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_12_MAP); setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_12_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_appliedFee_v06() throws Exception { public void testFailure_appliedFee_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_06_MAP); setEppInput("domain_update_restore_request_fee_applied.xml", FEE_06_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_appliedFee_v11() throws Exception { public void testFailure_appliedFee_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_11_MAP); setEppInput("domain_update_restore_request_fee_applied.xml", FEE_11_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_appliedFee_v12() throws Exception { public void testFailure_appliedFee_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_12_MAP); setEppInput("domain_update_restore_request_fee_applied.xml", FEE_12_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -340,9 +333,9 @@ public class DomainRestoreRequestFlowTest extends
@Test @Test
public void testFailure_doesNotExist() throws Exception { public void testFailure_doesNotExist() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -351,8 +344,7 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain(); persistPendingDeleteDomain();
persistResource( persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build()); Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -361,8 +353,7 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain(); persistPendingDeleteDomain();
persistResource( persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build()); Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -371,8 +362,7 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain(); persistPendingDeleteDomain();
persistResource( persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build()); Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
private void runWrongCurrencyTest(Map<String, String> substitutions) throws Exception { private void runWrongCurrencyTest(Map<String, String> substitutions) throws Exception {
@ -388,8 +378,7 @@ public class DomainRestoreRequestFlowTest extends
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
.setServerStatusChangeBillingCost(Money.of(EUR, 19)) .setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build()); .build());
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -411,24 +400,21 @@ public class DomainRestoreRequestFlowTest extends
public void testFailure_feeGivenInWrongScale_v06() throws Exception { public void testFailure_feeGivenInWrongScale_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_06_MAP); setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_06_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception { public void testFailure_feeGivenInWrongScale_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_11_MAP); setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_11_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception { public void testFailure_feeGivenInWrongScale_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_12_MAP); setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_12_MAP);
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(CurrencyValueScaleException.class); assertThrows(CurrencyValueScaleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -439,70 +425,63 @@ public class DomainRestoreRequestFlowTest extends
.setDeletionTime(clock.nowUtc().plusDays(4)) .setDeletionTime(clock.nowUtc().plusDays(4))
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.build()); .build());
thrown.expect(DomainNotEligibleForRestoreException.class); assertThrows(DomainNotEligibleForRestoreException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_notDeleted() throws Exception { public void testFailure_notDeleted() throws Exception {
persistActiveDomain(getUniqueIdFromCommand()); persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(DomainNotEligibleForRestoreException.class); assertThrows(DomainNotEligibleForRestoreException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_fullyDeleted() throws Exception { public void testFailure_fullyDeleted() throws Exception {
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class); assertThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_withChange() throws Exception { public void testFailure_withChange() throws Exception {
persistPendingDeleteDomain(); persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_change.xml"); setEppInput("domain_update_restore_request_with_change.xml");
thrown.expect(RestoreCommandIncludesChangesException.class); assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_withAdd() throws Exception { public void testFailure_withAdd() throws Exception {
persistPendingDeleteDomain(); persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_add.xml"); setEppInput("domain_update_restore_request_with_add.xml");
thrown.expect(RestoreCommandIncludesChangesException.class); assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_withRemove() throws Exception { public void testFailure_withRemove() throws Exception {
persistPendingDeleteDomain(); persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_remove.xml"); setEppInput("domain_update_restore_request_with_remove.xml");
thrown.expect(RestoreCommandIncludesChangesException.class); assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_withSecDnsExtension() throws Exception { public void testFailure_withSecDnsExtension() throws Exception {
persistPendingDeleteDomain(); persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_secdns.xml"); setEppInput("domain_update_restore_request_with_secdns.xml");
thrown.expect(UnimplementedExtensionException.class); assertThrows(UnimplementedExtensionException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_unauthorizedClient() throws Exception { public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testSuccess_superuserUnauthorizedClient() throws Exception { public void testSuccess_superuserUnauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(ResourceNotOwnedException.class); assertThrows(
runFlowAssertResponse(loadFile("domain_update_response.xml")); ResourceNotOwnedException.class,
() -> runFlowAssertResponse(loadFile("domain_update_response.xml")));
} }
@Test @Test
@ -510,8 +489,7 @@ public class DomainRestoreRequestFlowTest extends
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(NotAuthorizedForTldException.class); assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -530,8 +508,7 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain(); persistPendingDeleteDomain();
// Modify the Registrar to block premium names. // Modify the Registrar to block premium names.
persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build()); persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build());
thrown.expect(PremiumNameBlockedException.class); assertThrows(PremiumNameBlockedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -543,8 +520,7 @@ public class DomainRestoreRequestFlowTest extends
.setReservedLists(persistReservedList("tld-reserved", "example,FULLY_BLOCKED")) .setReservedLists(persistReservedList("tld-reserved", "example,FULLY_BLOCKED"))
.build()); .build());
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(DomainReservedException.class); assertThrows(DomainReservedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -552,8 +528,7 @@ public class DomainRestoreRequestFlowTest extends
createTld("example"); createTld("example");
setEppInput("domain_update_restore_request_premium.xml"); setEppInput("domain_update_restore_request_premium.xml");
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(FeesRequiredForPremiumNameException.class); assertThrows(FeesRequiredForPremiumNameException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -32,6 +32,8 @@ import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
@ -406,8 +408,9 @@ public class DomainTransferApproveFlowTest
contact.asBuilder() contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("domain_transfer_approve_contact_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_approve_contact_authinfo.xml"));
} }
@Test @Test
@ -416,89 +419,97 @@ public class DomainTransferApproveFlowTest
persistResource(domain.asBuilder() persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("domain_transfer_approve_domain_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_approve_domain_authinfo.xml"));
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_clientApproved() throws Exception { public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED); changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_clientRejected() throws Exception { public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED); changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_clientCancelled() throws Exception { public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED); changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_serverApproved() throws Exception { public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED); changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_serverCancelled() throws Exception { public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_approve.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_gainingClient() throws Exception { public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar"); setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class); assertThrows(
doFailingTest("domain_transfer_approve.xml"); ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
thrown.expect(ResourceNotOwnedException.class); assertThrows(
doFailingTest("domain_transfer_approve.xml"); ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_approve.xml"));
} }
@Test @Test
public void testFailure_deletedDomain() throws Exception { public void testFailure_deletedDomain() throws Exception {
persistResource( persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("domain_transfer_approve.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("domain_transfer_approve.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_nonexistentDomain() throws Exception { public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain); deleteResource(domain);
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("domain_transfer_approve.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("domain_transfer_approve.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_notAuthorizedForTld() throws Exception { public void testFailure_notAuthorizedForTld() throws Exception {
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class); assertThrows(
doSuccessfulTest("tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml"); NotAuthorizedForTldException.class,
() ->
doSuccessfulTest(
"tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml"));
} }
@Test @Test

View file

@ -29,6 +29,8 @@ import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -211,8 +213,9 @@ public class DomainTransferCancelFlowTest
contact.asBuilder() contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("domain_transfer_cancel_contact_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_cancel_contact_authinfo.xml"));
} }
@Test @Test
@ -221,89 +224,94 @@ public class DomainTransferCancelFlowTest
domain = persistResource(domain.asBuilder() domain = persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("domain_transfer_cancel_domain_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_cancel_domain_authinfo.xml"));
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_clientApproved() throws Exception { public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED); changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_clientRejected() throws Exception { public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED); changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_clientCancelled() throws Exception { public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED); changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_serverApproved() throws Exception { public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED); changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_serverCancelled() throws Exception { public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_cancel.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_sponsoringClient() throws Exception { public void testFailure_sponsoringClient() throws Exception {
setClientIdForFlow("TheRegistrar"); setClientIdForFlow("TheRegistrar");
thrown.expect(NotTransferInitiatorException.class); assertThrows(
doFailingTest("domain_transfer_cancel.xml"); NotTransferInitiatorException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
thrown.expect(NotTransferInitiatorException.class); assertThrows(
doFailingTest("domain_transfer_cancel.xml"); NotTransferInitiatorException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
} }
@Test @Test
public void testFailure_deletedDomain() throws Exception { public void testFailure_deletedDomain() throws Exception {
domain = persistResource( domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("domain_transfer_cancel.xml"); ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_nonexistentDomain() throws Exception { public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain); deleteResource(domain);
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("domain_transfer_cancel.xml"); ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_notAuthorizedForTld() throws Exception { public void testFailure_notAuthorizedForTld() throws Exception {
persistResource( persistResource(
loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class); assertThrows(
doSuccessfulTest("domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml"); NotAuthorizedForTldException.class,
() ->
doSuccessfulTest("domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml"));
} }
@Test @Test

View file

@ -20,6 +20,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.getPollMessages; import static google.registry.testing.DatastoreHelper.getPollMessages;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException; import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
@ -175,8 +177,9 @@ public class DomainTransferQueryFlowTest
contact.asBuilder() contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("domain_transfer_query_contact_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_query_contact_authinfo.xml"));
} }
@Test @Test
@ -185,39 +188,43 @@ public class DomainTransferQueryFlowTest
domain = persistResource(domain.asBuilder() domain = persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("domain_transfer_query_domain_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_query_domain_authinfo.xml"));
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
thrown.expect(NoTransferHistoryToQueryException.class); assertThrows(
doFailingTest("domain_transfer_query.xml"); NoTransferHistoryToQueryException.class, () -> doFailingTest("domain_transfer_query.xml"));
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
thrown.expect(NotAuthorizedToViewTransferException.class); assertThrows(
doFailingTest("domain_transfer_query.xml"); NotAuthorizedToViewTransferException.class,
() -> doFailingTest("domain_transfer_query.xml"));
} }
@Test @Test
public void testFailure_deletedDomain() throws Exception { public void testFailure_deletedDomain() throws Exception {
domain = persistResource( domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("domain_transfer_query.xml"); ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_query.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_nonexistentDomain() throws Exception { public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain); deleteResource(domain);
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("domain_transfer_query.xml"); ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_query.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test

View file

@ -31,6 +31,8 @@ import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -174,8 +176,10 @@ public class DomainTransferRejectFlowTest
public void testFailure_notAuthorizedForTld() throws Exception { public void testFailure_notAuthorizedForTld() throws Exception {
persistResource( persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class); assertThrows(
doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml"); NotAuthorizedForTldException.class,
() ->
doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml"));
} }
@Test @Test
@ -193,8 +197,9 @@ public class DomainTransferRejectFlowTest
contact.asBuilder() contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("domain_transfer_reject_contact_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_reject_contact_authinfo.xml"));
} }
@Test @Test
@ -204,81 +209,84 @@ public class DomainTransferRejectFlowTest
domain.asBuilder() domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("domain_transfer_reject_domain_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_reject_domain_authinfo.xml"));
} }
@Test @Test
public void testFailure_neverBeenTransferred() throws Exception { public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null); changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_clientApproved() throws Exception { public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED); changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_clientRejected() throws Exception { public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED); changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_clientCancelled() throws Exception { public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED); changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_serverApproved() throws Exception { public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED); changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_serverCancelled() throws Exception { public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_reject.xml"); NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_gainingClient() throws Exception { public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar"); setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class); assertThrows(
doFailingTest("domain_transfer_reject.xml"); ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_unrelatedClient() throws Exception { public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
thrown.expect(ResourceNotOwnedException.class); assertThrows(
doFailingTest("domain_transfer_reject.xml"); ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml"));
} }
@Test @Test
public void testFailure_deletedDomain() throws Exception { public void testFailure_deletedDomain() throws Exception {
domain = persistResource( domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("domain_transfer_reject.xml"); ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_nonexistentDomain() throws Exception { public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain); deleteResource(domain);
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("domain_transfer_reject.xml"); ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
// NB: No need to test pending delete status since pending transfers will get cancelled upon // NB: No need to test pending delete status since pending transfers will get cancelled upon

View file

@ -33,6 +33,8 @@ import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains; import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static java.util.stream.Collectors.toSet; import static java.util.stream.Collectors.toSet;
import static org.joda.money.CurrencyUnit.EUR; import static org.joda.money.CurrencyUnit.EUR;
@ -643,64 +645,73 @@ public class DomainTransferRequestFlowTest
@Test @Test
public void testFailure_refundableFee_v06() throws Exception { public void testFailure_refundableFee_v06() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_06_MAP); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_06_MAP));
} }
@Test @Test
public void testFailure_refundableFee_v11() throws Exception { public void testFailure_refundableFee_v11() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_11_MAP); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_11_MAP));
} }
@Test @Test
public void testFailure_refundableFee_v12() throws Exception { public void testFailure_refundableFee_v12() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_12_MAP); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_refundable.xml", FEE_12_MAP));
} }
@Test @Test
public void testFailure_gracePeriodFee_v06() throws Exception { public void testFailure_gracePeriodFee_v06() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_06_MAP); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_06_MAP));
} }
@Test @Test
public void testFailure_gracePeriodFee_v11() throws Exception { public void testFailure_gracePeriodFee_v11() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_11_MAP); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_11_MAP));
} }
@Test @Test
public void testFailure_gracePeriodFee_v12() throws Exception { public void testFailure_gracePeriodFee_v12() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_12_MAP); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_grace_period.xml", FEE_12_MAP));
} }
@Test @Test
public void testFailure_appliedFee_v06() throws Exception { public void testFailure_appliedFee_v06() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_applied.xml", FEE_06_MAP); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_06_MAP));
} }
@Test @Test
public void testFailure_appliedFee_v11() throws Exception { public void testFailure_appliedFee_v11() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_applied.xml", FEE_11_MAP); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_11_MAP));
} }
@Test @Test
public void testFailure_appliedFee_v12() throws Exception { public void testFailure_appliedFee_v12() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(UnsupportedFeeAttributeException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_applied.xml", FEE_12_MAP); UnsupportedFeeAttributeException.class,
() -> doFailingTest("domain_transfer_request_fee_applied.xml", FEE_12_MAP));
} }
@Test @Test
@ -739,8 +750,9 @@ public class DomainTransferRequestFlowTest
public void testFailure_multiYearPeriod() throws Exception { public void testFailure_multiYearPeriod() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(TransferPeriodMustBeOneYearException.class); assertThrows(
doFailingTest("domain_transfer_request_2_years.xml"); TransferPeriodMustBeOneYearException.class,
() -> doFailingTest("domain_transfer_request_2_years.xml"));
} }
@Test @Test
@ -826,11 +838,13 @@ public class DomainTransferRequestFlowTest
setupDomain("example", "tld"); setupDomain("example", "tld");
eppRequestSource = EppRequestSource.TOOL; eppRequestSource = EppRequestSource.TOOL;
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(InvalidTransferPeriodValueException.class); assertThrows(
runTest( InvalidTransferPeriodValueException.class,
"domain_transfer_request_superuser_extension.xml", () ->
UserPrivileges.SUPERUSER, runTest(
ImmutableMap.of("PERIOD", "2", "AUTOMATIC_TRANSFER_LENGTH", "5")); "domain_transfer_request_superuser_extension.xml",
UserPrivileges.SUPERUSER,
ImmutableMap.of("PERIOD", "2", "AUTOMATIC_TRANSFER_LENGTH", "5")));
} }
@Test @Test
@ -838,11 +852,13 @@ public class DomainTransferRequestFlowTest
setupDomain("example", "tld"); setupDomain("example", "tld");
eppRequestSource = EppRequestSource.TOOL; eppRequestSource = EppRequestSource.TOOL;
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(TransferPeriodZeroAndFeeTransferExtensionException.class); assertThrows(
runTest( TransferPeriodZeroAndFeeTransferExtensionException.class,
"domain_transfer_request_fee_and_superuser_extension.xml", () ->
UserPrivileges.SUPERUSER, runTest(
ImmutableMap.of("PERIOD", "0", "AUTOMATIC_TRANSFER_LENGTH", "5")); "domain_transfer_request_fee_and_superuser_extension.xml",
UserPrivileges.SUPERUSER,
ImmutableMap.of("PERIOD", "0", "AUTOMATIC_TRANSFER_LENGTH", "5")));
} }
@Test @Test
@ -894,8 +910,11 @@ public class DomainTransferRequestFlowTest
setupDomain("example", "tld"); setupDomain("example", "tld");
persistResource( persistResource(
loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class); assertThrows(
doSuccessfulTest("domain_transfer_request.xml", "domain_transfer_request_response.xml"); NotAuthorizedForTldException.class,
() ->
doSuccessfulTest(
"domain_transfer_request.xml", "domain_transfer_request_response.xml"));
} }
@Test @Test
@ -1035,8 +1054,9 @@ public class DomainTransferRequestFlowTest
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR))) .setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
.setServerStatusChangeBillingCost(Money.of(EUR, 19)) .setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build()); .build());
thrown.expect(CurrencyUnitMismatchException.class); assertThrows(
doFailingTest("domain_transfer_request_fee.xml", substitutions); CurrencyUnitMismatchException.class,
() -> doFailingTest("domain_transfer_request_fee.xml", substitutions));
} }
@Test @Test
@ -1060,22 +1080,25 @@ public class DomainTransferRequestFlowTest
@Test @Test
public void testFailure_feeGivenInWrongScale_v06() throws Exception { public void testFailure_feeGivenInWrongScale_v06() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(CurrencyValueScaleException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_06_MAP); CurrencyValueScaleException.class,
() -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_06_MAP));
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception { public void testFailure_feeGivenInWrongScale_v11() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(CurrencyValueScaleException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_11_MAP); CurrencyValueScaleException.class,
() -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_11_MAP));
} }
@Test @Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception { public void testFailure_feeGivenInWrongScale_v12() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(CurrencyValueScaleException.class); assertThrows(
doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_12_MAP); CurrencyValueScaleException.class,
() -> doFailingTest("domain_transfer_request_fee_bad_scale.xml", FEE_12_MAP));
} }
private void runWrongFeeAmountTest(Map<String, String> substitutions) throws Exception { private void runWrongFeeAmountTest(Map<String, String> substitutions) throws Exception {
@ -1084,8 +1107,9 @@ public class DomainTransferRequestFlowTest
.asBuilder() .asBuilder()
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20))) .setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build()); .build());
thrown.expect(FeesMismatchException.class); assertThrows(
doFailingTest("domain_transfer_request_fee.xml", substitutions); FeesMismatchException.class,
() -> doFailingTest("domain_transfer_request_fee.xml", substitutions));
} }
@Test @Test
@ -1112,22 +1136,25 @@ public class DomainTransferRequestFlowTest
// Modify the Registrar to block premium names. // Modify the Registrar to block premium names.
persistResource( persistResource(
loadRegistrar("NewRegistrar").asBuilder().setBlockPremiumNames(true).build()); loadRegistrar("NewRegistrar").asBuilder().setBlockPremiumNames(true).build());
thrown.expect(PremiumNameBlockedException.class); assertThrows(
doFailingTest("domain_transfer_request_premium.xml"); PremiumNameBlockedException.class,
() -> doFailingTest("domain_transfer_request_premium.xml"));
} }
@Test @Test
public void testFailure_feeNotProvidedOnPremiumName() throws Exception { public void testFailure_feeNotProvidedOnPremiumName() throws Exception {
setupDomain("rich", "example"); setupDomain("rich", "example");
thrown.expect(FeesRequiredForPremiumNameException.class); assertThrows(
doFailingTest("domain_transfer_request_premium.xml"); FeesRequiredForPremiumNameException.class,
() -> doFailingTest("domain_transfer_request_premium.xml"));
} }
@Test @Test
public void testFailure_noAuthInfo() throws Exception { public void testFailure_noAuthInfo() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(MissingTransferRequestAuthInfoException.class); assertThrows(
doFailingTest("domain_transfer_request_no_authinfo.xml"); MissingTransferRequestAuthInfoException.class,
() -> doFailingTest("domain_transfer_request_no_authinfo.xml"));
} }
@Test @Test
@ -1138,8 +1165,8 @@ public class DomainTransferRequestFlowTest
contact.asBuilder() contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("domain_transfer_request.xml"); BadAuthInfoForResourceException.class, () -> doFailingTest("domain_transfer_request.xml"));
} }
@Test @Test
@ -1148,8 +1175,8 @@ public class DomainTransferRequestFlowTest
// Set the contact to a different ROID, but don't persist it; this is just so the substitution // Set the contact to a different ROID, but don't persist it; this is just so the substitution
// code above will write the wrong ROID into the file. // code above will write the wrong ROID into the file.
contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build(); contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build();
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("domain_transfer_request.xml"); BadAuthInfoForResourceException.class, () -> doFailingTest("domain_transfer_request.xml"));
} }
@Test @Test
@ -1196,8 +1223,8 @@ public class DomainTransferRequestFlowTest
.setPendingTransferExpirationTime(clock.nowUtc().plusDays(1)) .setPendingTransferExpirationTime(clock.nowUtc().plusDays(1))
.build()) .build())
.build()); .build());
thrown.expect(AlreadyPendingTransferException.class); assertThrows(
doFailingTest("domain_transfer_request.xml"); AlreadyPendingTransferException.class, () -> doFailingTest("domain_transfer_request.xml"));
} }
@Test @Test
@ -1207,16 +1234,17 @@ public class DomainTransferRequestFlowTest
domain = persistResource(domain.asBuilder() domain = persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword"))) .setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build()); .build());
thrown.expect(BadAuthInfoForResourceException.class); assertThrows(
doFailingTest("domain_transfer_request_domain_authinfo.xml"); BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_request_domain_authinfo.xml"));
} }
@Test @Test
public void testFailure_sponsoringClient() throws Exception { public void testFailure_sponsoringClient() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
setClientIdForFlow("TheRegistrar"); setClientIdForFlow("TheRegistrar");
thrown.expect(ObjectAlreadySponsoredException.class); assertThrows(
doFailingTest("domain_transfer_request.xml"); ObjectAlreadySponsoredException.class, () -> doFailingTest("domain_transfer_request.xml"));
} }
@Test @Test
@ -1224,9 +1252,11 @@ public class DomainTransferRequestFlowTest
setupDomain("example", "tld"); setupDomain("example", "tld");
domain = persistResource( domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(
doFailingTest("domain_transfer_request.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("domain_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -1237,25 +1267,29 @@ public class DomainTransferRequestFlowTest
ImmutableMap.of("YEARS", "1", "DOMAIN", "--invalid", "EXDATE", "2002-09-08T22:00:00.0Z")); ImmutableMap.of("YEARS", "1", "DOMAIN", "--invalid", "EXDATE", "2002-09-08T22:00:00.0Z"));
eppLoader.replaceAll("JD1234-REP", contact.getRepoId()); eppLoader.replaceAll("JD1234-REP", contact.getRepoId());
assertTransactionalFlow(true); assertTransactionalFlow(true);
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage("(--invalid)"); expectThrows(
runFlow(CommitMode.LIVE, UserPrivileges.NORMAL); ResourceDoesNotExistException.class,
() -> runFlow(CommitMode.LIVE, UserPrivileges.NORMAL));
assertThat(thrown).hasMessageThat().contains("(--invalid)");
} }
@Test @Test
public void testFailure_nonexistentDomain() throws Exception { public void testFailure_nonexistentDomain() throws Exception {
createTld("tld"); createTld("tld");
contact = persistActiveContact("jd1234"); contact = persistActiveContact("jd1234");
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", "example.tld")); expectThrows(
doFailingTest("domain_transfer_request.xml"); ResourceDoesNotExistException.class,
() -> doFailingTest("domain_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", "example.tld"));
} }
@Test @Test
public void testFailure_periodInMonths() throws Exception { public void testFailure_periodInMonths() throws Exception {
setupDomain("example", "tld"); setupDomain("example", "tld");
thrown.expect(BadPeriodUnitException.class); assertThrows(
doFailingTest("domain_transfer_request_months.xml"); BadPeriodUnitException.class, () -> doFailingTest("domain_transfer_request_months.xml"));
} }
@Test @Test
@ -1263,9 +1297,11 @@ public class DomainTransferRequestFlowTest
setupDomain("example", "tld"); setupDomain("example", "tld");
domain = persistResource( domain = persistResource(
domain.asBuilder().addStatusValue(StatusValue.CLIENT_TRANSFER_PROHIBITED).build()); domain.asBuilder().addStatusValue(StatusValue.CLIENT_TRANSFER_PROHIBITED).build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("clientTransferProhibited"); expectThrows(
doFailingTest("domain_transfer_request.xml"); ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("domain_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("clientTransferProhibited");
} }
@Test @Test
@ -1273,9 +1309,11 @@ public class DomainTransferRequestFlowTest
setupDomain("example", "tld"); setupDomain("example", "tld");
domain = persistResource( domain = persistResource(
domain.asBuilder().addStatusValue(StatusValue.SERVER_TRANSFER_PROHIBITED).build()); domain.asBuilder().addStatusValue(StatusValue.SERVER_TRANSFER_PROHIBITED).build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("serverTransferProhibited"); expectThrows(
doFailingTest("domain_transfer_request.xml"); ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("domain_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("serverTransferProhibited");
} }
@Test @Test
@ -1283,9 +1321,11 @@ public class DomainTransferRequestFlowTest
setupDomain("example", "tld"); setupDomain("example", "tld");
domain = persistResource( domain = persistResource(
domain.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build()); domain.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("pendingDelete"); expectThrows(
doFailingTest("domain_transfer_request.xml"); ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("domain_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("pendingDelete");
} }
@Test @Test

View file

@ -440,8 +440,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_metadata.xml"); setEppInput("domain_update_metadata.xml");
persistReferencedEntities(); persistReferencedEntities();
persistDomain(); persistDomain();
thrown.expect(OnlyToolCanPassMetadataException.class); assertThrows(OnlyToolCanPassMetadataException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -795,8 +794,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
newDomainResource(getUniqueIdFromCommand()).asBuilder() newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setDsData(builder.build()) .setDsData(builder.build())
.build()); .build());
thrown.expect(TooManyDsRecordsException.class); assertThrows(TooManyDsRecordsException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -806,8 +804,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistDomain(); persistDomain();
// Modify domain so it has 13 nameservers. We will then try to add one in the test. // Modify domain so it has 13 nameservers. We will then try to add one in the test.
modifyDomainToHave13Nameservers(); modifyDomainToHave13Nameservers();
thrown.expect(TooManyNameserversException.class); assertThrows(TooManyNameserversException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -815,25 +812,24 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_wrong_extension.xml"); setEppInput("domain_update_wrong_extension.xml");
persistReferencedEntities(); persistReferencedEntities();
persistDomain(); persistDomain();
thrown.expect(UnimplementedExtensionException.class); assertThrows(UnimplementedExtensionException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
persistReferencedEntities(); persistReferencedEntities();
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistReferencedEntities(); persistReferencedEntities();
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1)); persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -842,9 +838,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistActiveContact("sh8013"); persistActiveContact("sh8013");
persistActiveContact("mak21"); persistActiveContact("mak21");
persistActiveDomain(getUniqueIdFromCommand()); persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(LinkedResourcesDoNotExistException.class); LinkedResourcesDoNotExistException thrown =
thrown.expectMessage("(ns2.example.foo)"); expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(ns2.example.foo)");
} }
@Test @Test
@ -853,9 +849,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistActiveHost("ns2.example.foo"); persistActiveHost("ns2.example.foo");
persistActiveContact("mak21"); persistActiveContact("mak21");
persistActiveDomain(getUniqueIdFromCommand()); persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(LinkedResourcesDoNotExistException.class); LinkedResourcesDoNotExistException thrown =
thrown.expectMessage("(sh8013)"); expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(sh8013)");
} }
@Test @Test
@ -871,8 +867,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
DesignatedContact.create(Type.TECH, Key.create( DesignatedContact.create(Type.TECH, Key.create(
loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))) loadByForeignKey(ContactResource.class, "foo", clock.nowUtc())))))
.build()); .build());
thrown.expect(DuplicateContactForRoleException.class); assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -880,8 +875,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_prohibited_status.xml"); setEppInput("domain_update_prohibited_status.xml");
persistReferencedEntities(); persistReferencedEntities();
persistDomain(); persistDomain();
thrown.expect(StatusNotClientSettableException.class); assertThrows(StatusNotClientSettableException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -941,8 +935,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
newDomainResource(getUniqueIdFromCommand()).asBuilder() newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)) .setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build()); .build());
thrown.expect(ResourceHasClientUpdateProhibitedException.class); assertThrows(ResourceHasClientUpdateProhibitedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -952,9 +945,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
newDomainResource(getUniqueIdFromCommand()).asBuilder() newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(SERVER_UPDATE_PROHIBITED)) .setStatusValues(ImmutableSet.of(SERVER_UPDATE_PROHIBITED))
.build()); .build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("serverUpdateProhibited"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited");
} }
@Test @Test
@ -965,9 +958,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setDeletionTime(clock.nowUtc().plusDays(1)) .setDeletionTime(clock.nowUtc().plusDays(1))
.addStatusValue(StatusValue.PENDING_DELETE) .addStatusValue(StatusValue.PENDING_DELETE)
.build()); .build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("pendingDelete"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("pendingDelete");
} }
@Test @Test
@ -975,8 +968,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_duplicate_contact.xml"); setEppInput("domain_update_duplicate_contact.xml");
persistReferencedEntities(); persistReferencedEntities();
persistDomain(); persistDomain();
thrown.expect(DuplicateContactForRoleException.class); assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -985,8 +977,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_missing_contact_type.xml"); setEppInput("domain_update_missing_contact_type.xml");
persistReferencedEntities(); persistReferencedEntities();
persistDomain(); persistDomain();
thrown.expect(MissingContactTypeException.class); assertThrows(MissingContactTypeException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -994,8 +985,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistReferencedEntities(); persistReferencedEntities();
persistDomain(); persistDomain();
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1014,8 +1004,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistReferencedEntities(); persistReferencedEntities();
persistDomain(); persistDomain();
thrown.expect(NotAuthorizedForTldException.class); assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1038,8 +1027,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setNameservers(ImmutableSet.of(Key.create( .setNameservers(ImmutableSet.of(Key.create(
loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc())))) loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()))))
.build()); .build());
thrown.expect(AddRemoveSameValueException.class); assertThrows(AddRemoveSameValueException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1053,8 +1041,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
Key.create( Key.create(
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc()))))) loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())))))
.build()); .build());
thrown.expect(AddRemoveSameValueException.class); assertThrows(AddRemoveSameValueException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1067,8 +1054,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) DesignatedContact.create(Type.TECH, Key.create(sh8013Contact))))
.build()); .build());
thrown.expect(MissingAdminContactException.class); assertThrows(MissingAdminContactException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1081,8 +1067,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)), DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact)))) DesignatedContact.create(Type.TECH, Key.create(sh8013Contact))))
.build()); .build());
thrown.expect(MissingTechnicalContactException.class); assertThrows(MissingTechnicalContactException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1096,9 +1081,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.addStatusValue(StatusValue.PENDING_DELETE) .addStatusValue(StatusValue.PENDING_DELETE)
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(LinkedResourceInPendingDeleteProhibitsOperationException.class); LinkedResourceInPendingDeleteProhibitsOperationException thrown =
thrown.expectMessage("mak21"); expectThrows(
runFlow(); LinkedResourceInPendingDeleteProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("mak21");
} }
@Test @Test
@ -1113,9 +1099,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.addStatusValue(StatusValue.PENDING_DELETE) .addStatusValue(StatusValue.PENDING_DELETE)
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(LinkedResourceInPendingDeleteProhibitsOperationException.class); LinkedResourceInPendingDeleteProhibitsOperationException thrown =
thrown.expectMessage("ns2.example.foo"); expectThrows(
runFlow(); LinkedResourceInPendingDeleteProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns2.example.foo");
} }
@Test @Test
@ -1127,8 +1114,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setAllowedRegistrantContactIds(ImmutableSet.of("contact1234")) .setAllowedRegistrantContactIds(ImmutableSet.of("contact1234"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(RegistrantNotAllowedException.class); assertThrows(RegistrantNotAllowedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1140,8 +1126,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForTldException.class); assertThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1223,8 +1208,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
Registry.get("tld").asBuilder() Registry.get("tld").asBuilder()
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo")) .setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
.build()); .build());
thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class); assertThrows(
runFlow(); NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, () -> runFlow());
} }
@Test @Test
@ -1252,9 +1237,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList( persistReservedList(
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns3.example.foo")) "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns3.example.foo"))
.build()); .build());
thrown.expect(NameserversNotAllowedForDomainException.class); NameserversNotAllowedForDomainException thrown =
thrown.expectMessage("ns2.example.foo"); expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns2.example.foo");
} }
@Test @Test
@ -1269,8 +1254,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList( persistReservedList(
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo")) "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo"))
.build()); .build());
thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class); assertThrows(
runFlow(); NameserversNotSpecifiedForNameserverRestrictedDomainException.class, () -> runFlow());
} }
@Test @Test
@ -1314,9 +1299,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList( persistReservedList(
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns3.example.foo")) "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns3.example.foo"))
.build()); .build());
thrown.expect(NameserversNotAllowedForDomainException.class); NameserversNotAllowedForDomainException thrown =
thrown.expectMessage("ns2.example.foo"); expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns2.example.foo");
} }
@Test @Test
@ -1349,9 +1334,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setReservedLists( .setReservedLists(
persistReservedList("reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo")) persistReservedList("reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo"))
.build()); .build());
thrown.expect(NameserversNotAllowedForDomainException.class); NameserversNotAllowedForDomainException thrown =
thrown.expectMessage("ns2.example.foo"); expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns2.example.foo");
} }
@Test @Test
@ -1367,9 +1352,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList( persistReservedList(
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo")) "reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo"))
.build()); .build());
thrown.expect(NameserversNotAllowedForTldException.class); NameserversNotAllowedForTldException thrown =
thrown.expectMessage("ns2.example.foo"); expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns2.example.foo");
} }
@Test @Test
@ -1387,8 +1372,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList( persistReservedList(
"reserved", "lol,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo")) "reserved", "lol,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo"))
.build()); .build());
thrown.expect(DomainNotAllowedForTldWithCreateRestrictionException.class); assertThrows(DomainNotAllowedForTldWithCreateRestrictionException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1403,8 +1387,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList( persistReservedList(
"reserved", "lol,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo")) "reserved", "lol,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo"))
.build()); .build());
thrown.expect(DomainNotAllowedForTldWithCreateRestrictionException.class); assertThrows(DomainNotAllowedForTldWithCreateRestrictionException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1458,8 +1441,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11")); setEppInput("domain_update_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistReferencedEntities(); persistReferencedEntities();
persistDomain(); persistDomain();
thrown.expect(FeesMismatchException.class); assertThrows(FeesMismatchException.class, () -> runFlow());
runFlow();
} }
// This test should throw an exception, because the fee extension is required when the fee is not // This test should throw an exception, because the fee extension is required when the fee is not
@ -1469,8 +1451,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_wildcard.xml", ImmutableMap.of("DOMAIN", "non-free-update.tld")); setEppInput("domain_update_wildcard.xml", ImmutableMap.of("DOMAIN", "non-free-update.tld"));
persistReferencedEntities(); persistReferencedEntities();
persistDomain(); persistDomain();
thrown.expect(FeesRequiredForNonFreeOperationException.class); assertThrows(FeesRequiredForNonFreeOperationException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -17,6 +17,7 @@ package google.registry.flows.host;
import static google.registry.model.eppoutput.CheckData.HostCheck.create; import static google.registry.model.eppoutput.CheckData.HostCheck.create;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.JUnitBackports.assertThrows;
import google.registry.flows.ResourceCheckFlowTestCase; import google.registry.flows.ResourceCheckFlowTestCase;
import google.registry.flows.exceptions.TooManyResourceChecksException; import google.registry.flows.exceptions.TooManyResourceChecksException;
@ -75,8 +76,7 @@ public class HostCheckFlowTest extends ResourceCheckFlowTestCase<HostCheckFlow,
@Test @Test
public void testTooManyIds() throws Exception { public void testTooManyIds() throws Exception {
setEppInput("host_check_51.xml"); setEppInput("host_check_51.xml");
thrown.expect(TooManyResourceChecksException.class); assertThrows(TooManyResourceChecksException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -26,6 +26,7 @@ import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
@ -125,8 +126,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
createTlds("bar.tld", "tld"); createTlds("bar.tld", "tld");
setEppHostCreateInputWithIps("ns1.bar.tld"); setEppHostCreateInputWithIps("ns1.bar.tld");
thrown.expect(HostNameTooShallowException.class); assertThrows(HostNameTooShallowException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -154,8 +154,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
setEppHostCreateInput("ns1.example.tld", null); setEppHostCreateInput("ns1.example.tld", null);
createTld("tld"); createTld("tld");
persistActiveDomain("example.tld"); persistActiveDomain("example.tld");
thrown.expect(SubordinateHostMustHaveIpException.class); assertThrows(SubordinateHostMustHaveIpException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -163,17 +162,16 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
setEppHostCreateInputWithIps("ns1.example.external"); setEppHostCreateInputWithIps("ns1.example.external");
createTld("tld"); createTld("tld");
persistActiveDomain("example.tld"); persistActiveDomain("example.tld");
thrown.expect(UnexpectedExternalHostIpException.class); assertThrows(UnexpectedExternalHostIpException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_superordinateMissing() throws Exception { public void testFailure_superordinateMissing() throws Exception {
setEppHostCreateInput("ns1.example.tld", null); setEppHostCreateInput("ns1.example.tld", null);
createTld("tld"); createTld("tld");
thrown.expect(SuperordinateDomainDoesNotExistException.class); SuperordinateDomainDoesNotExistException thrown =
thrown.expectMessage("(example.tld)"); expectThrows(SuperordinateDomainDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(example.tld)");
} }
@Test @Test
@ -186,48 +184,49 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.build()); .build());
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SuperordinateDomainInPendingDeleteException.class); SuperordinateDomainInPendingDeleteException thrown =
thrown.expectMessage("Superordinate domain for this hostname is in pending delete"); expectThrows(SuperordinateDomainInPendingDeleteException.class, () -> runFlow());
runFlow(); assertThat(thrown)
.hasMessageThat()
.contains("Superordinate domain for this hostname is in pending delete");
} }
@Test @Test
public void testFailure_alreadyExists() throws Exception { public void testFailure_alreadyExists() throws Exception {
setEppHostCreateInput("ns1.example.tld", null); setEppHostCreateInput("ns1.example.tld", null);
persistActiveHost(getUniqueIdFromCommand()); persistActiveHost(getUniqueIdFromCommand());
thrown.expect(ResourceAlreadyExistsException.class); ResourceAlreadyExistsException thrown =
thrown.expectMessage( expectThrows(ResourceAlreadyExistsException.class, () -> runFlow());
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand())); assertThat(thrown)
runFlow(); .hasMessageThat()
.contains(
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_nonLowerCaseHostname() throws Exception { public void testFailure_nonLowerCaseHostname() throws Exception {
setEppHostCreateInput("ns1.EXAMPLE.tld", null); setEppHostCreateInput("ns1.EXAMPLE.tld", null);
thrown.expect(HostNameNotLowerCaseException.class); assertThrows(HostNameNotLowerCaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_nonPunyCodedHostname() throws Exception { public void testFailure_nonPunyCodedHostname() throws Exception {
setEppHostCreateInput("ns1.çauçalito.みんな", null); setEppHostCreateInput("ns1.çauçalito.みんな", null);
thrown.expect(HostNameNotPunyCodedException.class); HostNameNotPunyCodedException thrown =
thrown.expectMessage("expected ns1.xn--aualito-txac.xn--q9jyb4c"); expectThrows(HostNameNotPunyCodedException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.xn--q9jyb4c");
} }
@Test @Test
public void testFailure_nonCanonicalHostname() throws Exception { public void testFailure_nonCanonicalHostname() throws Exception {
setEppHostCreateInput("ns1.example.tld.", null); setEppHostCreateInput("ns1.example.tld.", null);
thrown.expect(HostNameNotNormalizedException.class); assertThrows(HostNameNotNormalizedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_longHostName() throws Exception { public void testFailure_longHostName() throws Exception {
setEppHostCreateInputWithIps("a" + Strings.repeat(".labelpart", 25) + ".tld"); setEppHostCreateInputWithIps("a" + Strings.repeat(".labelpart", 25) + ".tld");
thrown.expect(HostNameTooLongException.class); assertThrows(HostNameTooLongException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -237,8 +236,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
"<host:addr ip=\"v4\">192.0.2.2</host:addr>\n" "<host:addr ip=\"v4\">192.0.2.2</host:addr>\n"
+ "<host:addr ip=\"v6\">192.0.2.29</host:addr>\n" + "<host:addr ip=\"v6\">192.0.2.29</host:addr>\n"
+ "<host:addr ip=\"v6\">1080:0:0:0:8:800:200C:417A</host:addr>"); + "<host:addr ip=\"v6\">1080:0:0:0:8:800:200C:417A</host:addr>");
thrown.expect(IpAddressVersionMismatchException.class); assertThrows(IpAddressVersionMismatchException.class, () -> runFlow());
runFlow();
} }
private void doFailingHostNameTest(String hostName, Class<? extends Throwable> exception) private void doFailingHostNameTest(String hostName, Class<? extends Throwable> exception)
@ -281,8 +279,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
public void testFailure_ccTldInBailiwick() throws Exception { public void testFailure_ccTldInBailiwick() throws Exception {
createTld("co.uk"); createTld("co.uk");
setEppHostCreateInputWithIps("foo.co.uk"); setEppHostCreateInputWithIps("foo.co.uk");
thrown.expect(HostNameTooShallowException.class); assertThrows(HostNameTooShallowException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -24,6 +24,7 @@ import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
@ -83,17 +84,17 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage("(ns1.example.tld)"); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(ns1.example.tld)");
} }
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1)); persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage("(ns1.example.tld)"); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(ns1.example.tld)");
} }
private void doFailingStatusTest(StatusValue statusValue, Class<? extends Exception> exception) private void doFailingStatusTest(StatusValue statusValue, Class<? extends Exception> exception)
@ -129,8 +130,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
public void testFailure_unauthorizedClient() throws Exception { public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistActiveHost("ns1.example.tld"); persistActiveHost("ns1.example.tld");
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -181,8 +181,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
.setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't help. .setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't help.
.setSuperordinateDomain(Key.create(domain)) .setSuperordinateDomain(Key.create(domain))
.build()); .build());
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -237,8 +236,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
.setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't help. .setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't help.
.setSuperordinateDomain(Key.create(domain)) .setSuperordinateDomain(Key.create(domain))
.build()); .build());
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -248,8 +246,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
.setNameservers(ImmutableSet.of( .setNameservers(ImmutableSet.of(
Key.create(persistActiveHost("ns1.example.tld")))) Key.create(persistActiveHost("ns1.example.tld"))))
.build()); .build());
thrown.expect(ResourceToDeleteIsReferencedException.class); assertThrows(ResourceToDeleteIsReferencedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -259,30 +256,27 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
.setNameservers(ImmutableSet.of( .setNameservers(ImmutableSet.of(
Key.create(persistActiveHost("ns1.example.tld")))) Key.create(persistActiveHost("ns1.example.tld"))))
.build()); .build());
thrown.expect(ResourceToDeleteIsReferencedException.class); assertThrows(ResourceToDeleteIsReferencedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_nonLowerCaseHostname() throws Exception { public void testFailure_nonLowerCaseHostname() throws Exception {
setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "NS1.EXAMPLE.NET")); setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "NS1.EXAMPLE.NET"));
thrown.expect(HostNameNotLowerCaseException.class); assertThrows(HostNameNotLowerCaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_nonPunyCodedHostname() throws Exception { public void testFailure_nonPunyCodedHostname() throws Exception {
setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.çauçalito.tld")); setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.çauçalito.tld"));
thrown.expect(HostNameNotPunyCodedException.class); HostNameNotPunyCodedException thrown =
thrown.expectMessage("expected ns1.xn--aualito-txac.tld"); expectThrows(HostNameNotPunyCodedException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.tld");
} }
@Test @Test
public void testFailure_nonCanonicalHostname() throws Exception { public void testFailure_nonCanonicalHostname() throws Exception {
setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld.")); setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld."));
thrown.expect(HostNameNotNormalizedException.class); assertThrows(HostNameNotNormalizedException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -14,10 +14,13 @@
package google.registry.flows.host; package google.registry.flows.host;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents; import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -143,40 +146,38 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistResource( persistResource(
persistHostResource().asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); persistHostResource().asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_nonLowerCaseHostname() throws Exception { public void testFailure_nonLowerCaseHostname() throws Exception {
setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "NS1.EXAMPLE.NET")); setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "NS1.EXAMPLE.NET"));
thrown.expect(HostNameNotLowerCaseException.class); assertThrows(HostNameNotLowerCaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_nonPunyCodedHostname() throws Exception { public void testFailure_nonPunyCodedHostname() throws Exception {
setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "ns1.çauçalito.tld")); setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "ns1.çauçalito.tld"));
thrown.expect(HostNameNotPunyCodedException.class); HostNameNotPunyCodedException thrown =
thrown.expectMessage("expected ns1.xn--aualito-txac.tld"); expectThrows(HostNameNotPunyCodedException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.tld");
} }
@Test @Test
public void testFailure_nonCanonicalHostname() throws Exception { public void testFailure_nonCanonicalHostname() throws Exception {
setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld.")); setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld."));
thrown.expect(HostNameNotNormalizedException.class); assertThrows(HostNameNotNormalizedException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -408,8 +408,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
null, null,
null); null);
persistActiveHost(oldHostName()); persistActiveHost(oldHostName());
thrown.expect(CannotRenameExternalHostException.class); assertThrows(CannotRenameExternalHostException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -760,9 +759,9 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
public void testFailure_superordinateMissing() throws Exception { public void testFailure_superordinateMissing() throws Exception {
createTld("tld"); createTld("tld");
persistActiveHost(oldHostName()); persistActiveHost(oldHostName());
thrown.expect(SuperordinateDomainDoesNotExistException.class); SuperordinateDomainDoesNotExistException thrown =
thrown.expectMessage("(example.tld)"); expectThrows(SuperordinateDomainDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("(example.tld)");
} }
@Test @Test
@ -781,32 +780,34 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.build()); .build());
persistActiveSubordinateHost(oldHostName(), domain); persistActiveSubordinateHost(oldHostName(), domain);
clock.advanceOneMilli(); clock.advanceOneMilli();
thrown.expect(SuperordinateDomainInPendingDeleteException.class); SuperordinateDomainInPendingDeleteException thrown =
thrown.expectMessage("Superordinate domain for this hostname is in pending delete"); expectThrows(SuperordinateDomainInPendingDeleteException.class, () -> runFlow());
runFlow(); assertThat(thrown)
.hasMessageThat()
.contains("Superordinate domain for this hostname is in pending delete");
} }
@Test @Test
public void testFailure_neverExisted() throws Exception { public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_neverExisted_updateWithoutNameChange() throws Exception { public void testFailure_neverExisted_updateWithoutNameChange() throws Exception {
setEppInput("host_update_name_unchanged.xml"); setEppInput("host_update_name_unchanged.xml");
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
public void testFailure_existedButWasDeleted() throws Exception { public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedHost(oldHostName(), clock.nowUtc().minusDays(1)); persistDeletedHost(oldHostName(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class); ResourceDoesNotExistException thrown =
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand())); expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @Test
@ -815,9 +816,9 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld")); persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld"));
clock.advanceOneMilli(); clock.advanceOneMilli();
setEppHostUpdateInput("ns1.example.tld", "ns1.example.tld", null, null); setEppHostUpdateInput("ns1.example.tld", "ns1.example.tld", null, null);
thrown.expect(HostAlreadyExistsException.class); HostAlreadyExistsException thrown =
thrown.expectMessage("ns1.example.tld"); expectThrows(HostAlreadyExistsException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns1.example.tld");
} }
@Test @Test
@ -825,57 +826,53 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
createTld("tld"); createTld("tld");
persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld")); persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld"));
persistActiveHost("ns2.example.tld"); persistActiveHost("ns2.example.tld");
thrown.expect(HostAlreadyExistsException.class); HostAlreadyExistsException thrown =
thrown.expectMessage("ns2.example.tld"); expectThrows(HostAlreadyExistsException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("ns2.example.tld");
} }
@Test @Test
public void testFailure_referToNonLowerCaseHostname() throws Exception { public void testFailure_referToNonLowerCaseHostname() throws Exception {
setEppHostUpdateInput("ns1.EXAMPLE.tld", "ns2.example.tld", null, null); setEppHostUpdateInput("ns1.EXAMPLE.tld", "ns2.example.tld", null, null);
thrown.expect(HostNameNotLowerCaseException.class); assertThrows(HostNameNotLowerCaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_renameToNonLowerCaseHostname() throws Exception { public void testFailure_renameToNonLowerCaseHostname() throws Exception {
persistActiveHost("ns1.example.tld"); persistActiveHost("ns1.example.tld");
setEppHostUpdateInput("ns1.example.tld", "ns2.EXAMPLE.tld", null, null); setEppHostUpdateInput("ns1.example.tld", "ns2.EXAMPLE.tld", null, null);
thrown.expect(HostNameNotLowerCaseException.class); assertThrows(HostNameNotLowerCaseException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_referToNonPunyCodedHostname() throws Exception { public void testFailure_referToNonPunyCodedHostname() throws Exception {
setEppHostUpdateInput("ns1.çauçalito.tld", "ns1.sausalito.tld", null, null); setEppHostUpdateInput("ns1.çauçalito.tld", "ns1.sausalito.tld", null, null);
thrown.expect(HostNameNotPunyCodedException.class); HostNameNotPunyCodedException thrown =
thrown.expectMessage("expected ns1.xn--aualito-txac.tld"); expectThrows(HostNameNotPunyCodedException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.tld");
} }
@Test @Test
public void testFailure_renameToNonPunyCodedHostname() throws Exception { public void testFailure_renameToNonPunyCodedHostname() throws Exception {
persistActiveHost("ns1.sausalito.tld"); persistActiveHost("ns1.sausalito.tld");
setEppHostUpdateInput("ns1.sausalito.tld", "ns1.çauçalito.tld", null, null); setEppHostUpdateInput("ns1.sausalito.tld", "ns1.çauçalito.tld", null, null);
thrown.expect(HostNameNotPunyCodedException.class); HostNameNotPunyCodedException thrown =
thrown.expectMessage("expected ns1.xn--aualito-txac.tld"); expectThrows(HostNameNotPunyCodedException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.tld");
} }
@Test @Test
public void testFailure_referToNonCanonicalHostname() throws Exception { public void testFailure_referToNonCanonicalHostname() throws Exception {
persistActiveHost("ns1.example.tld."); persistActiveHost("ns1.example.tld.");
setEppHostUpdateInput("ns1.example.tld.", "ns2.example.tld", null, null); setEppHostUpdateInput("ns1.example.tld.", "ns2.example.tld", null, null);
thrown.expect(HostNameNotNormalizedException.class); assertThrows(HostNameNotNormalizedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
public void testFailure_renameToNonCanonicalHostname() throws Exception { public void testFailure_renameToNonCanonicalHostname() throws Exception {
persistActiveHost("ns1.example.tld"); persistActiveHost("ns1.example.tld");
setEppHostUpdateInput("ns1.example.tld", "ns2.example.tld.", null, null); setEppHostUpdateInput("ns1.example.tld", "ns2.example.tld.", null, null);
thrown.expect(HostNameNotNormalizedException.class); assertThrows(HostNameNotNormalizedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -887,8 +884,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
"<host:addr ip=\"v6\">1080:0:0:0:8:800:200C:417A</host:addr>"); "<host:addr ip=\"v6\">1080:0:0:0:8:800:200C:417A</host:addr>");
createTld("tld"); createTld("tld");
persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld")); persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld"));
thrown.expect(CannotRemoveSubordinateHostLastIpException.class); assertThrows(CannotRemoveSubordinateHostLastIpException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -900,8 +896,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
null); null);
createTld("tld"); createTld("tld");
persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld")); persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld"));
thrown.expect(RenameHostToExternalRemoveIpException.class); assertThrows(RenameHostToExternalRemoveIpException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -913,8 +908,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
null); null);
createTld("tld"); createTld("tld");
persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld")); persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld"));
thrown.expect(CannotAddIpToExternalHostException.class); assertThrows(CannotAddIpToExternalHostException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -927,8 +921,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
"<host:status s=\"clientUpdateProhibited\"/>", "<host:status s=\"clientUpdateProhibited\"/>",
"<host:status s=\"clientUpdateProhibited\"/>"); "<host:status s=\"clientUpdateProhibited\"/>");
persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld")); persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld"));
thrown.expect(AddRemoveSameValueException.class); assertThrows(AddRemoveSameValueException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -940,8 +933,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
"ns2.example.tld", "ns2.example.tld",
"<host:addr ip=\"v4\">192.0.2.22</host:addr>", "<host:addr ip=\"v4\">192.0.2.22</host:addr>",
"<host:addr ip=\"v4\">192.0.2.22</host:addr>"); "<host:addr ip=\"v4\">192.0.2.22</host:addr>");
thrown.expect(AddRemoveSameValueException.class); assertThrows(AddRemoveSameValueException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -965,8 +957,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)) .setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.setSuperordinateDomain(Key.create(persistActiveDomain("example.tld"))) .setSuperordinateDomain(Key.create(persistActiveDomain("example.tld")))
.build()); .build());
thrown.expect(ResourceHasClientUpdateProhibitedException.class); assertThrows(ResourceHasClientUpdateProhibitedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -977,9 +968,9 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED)) .setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED))
.setSuperordinateDomain(Key.create(persistActiveDomain("example.tld"))) .setSuperordinateDomain(Key.create(persistActiveDomain("example.tld")))
.build()); .build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("serverUpdateProhibited"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited");
} }
@Test @Test
@ -990,9 +981,9 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.setSuperordinateDomain(Key.create(persistActiveDomain("example.tld"))) .setSuperordinateDomain(Key.create(persistActiveDomain("example.tld")))
.build()); .build());
thrown.expect(ResourceStatusProhibitsOperationException.class); ResourceStatusProhibitsOperationException thrown =
thrown.expectMessage("pendingDelete"); expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
runFlow(); assertThat(thrown).hasMessageThat().contains("pendingDelete");
} }
@Test @Test
@ -1000,8 +991,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
createTld("tld"); createTld("tld");
persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld")); persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld"));
setEppInput("host_update_prohibited_status.xml"); setEppInput("host_update_prohibited_status.xml");
thrown.expect(StatusNotClientSettableException.class); assertThrows(StatusNotClientSettableException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1022,8 +1012,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
public void testFailure_unauthorizedClient() throws Exception { public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistActiveHost("ns1.example.tld"); persistActiveHost("ns1.example.tld");
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1070,8 +1059,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1"))) .setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.build()); .build());
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1104,8 +1092,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
.setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1"))) .setInetAddresses(ImmutableSet.of(InetAddresses.forString("127.0.0.1")))
.build()); .build());
thrown.expect(ResourceNotOwnedException.class); assertThrows(ResourceNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1125,8 +1112,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.foo")); persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.foo"));
assertAboutHosts().that(host).hasPersistedCurrentSponsorClientId("TheRegistrar"); assertAboutHosts().that(host).hasPersistedCurrentSponsorClientId("TheRegistrar");
thrown.expect(HostDomainNotOwnedException.class); assertThrows(HostDomainNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test
@ -1146,8 +1132,7 @@ public class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Hos
assertAboutDomains().that(domain).hasPersistedCurrentSponsorClientId("TheRegistrar"); assertAboutDomains().that(domain).hasPersistedCurrentSponsorClientId("TheRegistrar");
assertAboutHosts().that(host).hasPersistedCurrentSponsorClientId("TheRegistrar"); assertAboutHosts().that(host).hasPersistedCurrentSponsorClientId("TheRegistrar");
thrown.expect(HostDomainNotOwnedException.class); assertThrows(HostDomainNotOwnedException.class, () -> runFlow());
runFlow();
} }
@Test @Test

View file

@ -20,6 +20,7 @@ import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import google.registry.flows.FlowTestCase; import google.registry.flows.FlowTestCase;
@ -220,7 +221,6 @@ public class PollRequestFlowTest extends FlowTestCase<PollRequestFlow> {
public void testFailure_messageIdProvided() throws Exception { public void testFailure_messageIdProvided() throws Exception {
setEppInput("poll_with_id.xml"); setEppInput("poll_with_id.xml");
assertTransactionalFlow(false); assertTransactionalFlow(false);
thrown.expect(UnexpectedMessageIdException.class); assertThrows(UnexpectedMessageIdException.class, () -> runFlow());
runFlow();
} }
} }

View file

@ -15,6 +15,7 @@
package google.registry.flows.session; package google.registry.flows.session;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.JUnitBackports.assertThrows;
import google.registry.flows.FlowTestCase; import google.registry.flows.FlowTestCase;
import google.registry.flows.FlowUtils.NotLoggedInException; import google.registry.flows.FlowUtils.NotLoggedInException;
@ -43,7 +44,6 @@ public class LogoutFlowTest extends FlowTestCase<LogoutFlow> {
@Test @Test
public void testFailure() throws Exception { public void testFailure() throws Exception {
sessionMetadata.setClientId(null); // Turn off the implicit login sessionMetadata.setClientId(null); // Turn off the implicit login
thrown.expect(NotLoggedInException.class); assertThrows(NotLoggedInException.class, () -> runFlow());
runFlow();
} }
} }

View file

@ -28,6 +28,7 @@ import static google.registry.testing.DatastoreHelper.newDomainApplication;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
@ -131,20 +132,21 @@ public class AllocateDomainCommandTest extends CommandTestCase<AllocateDomainCom
@Test @Test
public void testFailure_notAsSuperuser() throws Exception { public void testFailure_notAsSuperuser() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--ids=1-TLD", "--force"));
runCommand("--ids=1-TLD", "--force");
} }
@Test @Test
public void testFailure_forceAndDryRunIncompatible() throws Exception { public void testFailure_forceAndDryRunIncompatible() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--ids=1-TLD", "--force", "--dry_run", "--superuser"); IllegalArgumentException.class,
() -> runCommand("--ids=1-TLD", "--force", "--dry_run", "--superuser"));
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--ids=1-TLD", "--force", "--unrecognized=foo", "--superuser"); ParameterException.class,
() -> runCommand("--ids=1-TLD", "--force", "--unrecognized=foo", "--superuser"));
} }
@Test @Test

View file

@ -15,6 +15,7 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.assertThrows;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -28,9 +29,7 @@ import com.google.api.client.util.store.DataStore;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -61,9 +60,6 @@ public class AuthModuleTest {
return result; return result;
} }
} }
@Rule public final ExpectedException thrown = ExpectedException.none();
@Test @Test
public void test_clientScopeQualifier() { public void test_clientScopeQualifier() {
AuthModule authModule = new AuthModule(); AuthModule authModule = new AuthModule();
@ -129,9 +125,8 @@ public class AuthModuleTest {
@Test @Test
public void test_provideCredential_notStored() { public void test_provideCredential_notStored() {
thrown.expect(AuthModule.LoginRequiredException.class);
// Doing this without the mock setup should cause us to throw an exception because the // Doing this without the mock setup should cause us to throw an exception because the
// credential has not been stored. // credential has not been stored.
getCredential(); assertThrows(AuthModule.LoginRequiredException.class, () -> getCredential());
} }
} }

View file

@ -39,7 +39,6 @@ import java.io.PrintStream;
import java.util.List; import java.util.List;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
@ -63,9 +62,6 @@ public abstract class CommandTestCase<C extends Command> {
.withTaskQueue() .withTaskQueue()
.build(); .build();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule @Rule
public TemporaryFolder tmpDir = new TemporaryFolder(); public TemporaryFolder tmpDir = new TemporaryFolder();

View file

@ -17,6 +17,7 @@ package google.registry.tools;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
@ -83,43 +84,80 @@ public class CreateAnchorTenantCommandTest
@Test @Test
public void testFailure_mainParameter() throws Exception { public void testFailure_mainParameter() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--tld=tld", "--client=NewRegistrar", "--superuser", ParameterException.class,
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld", "foo"); () ->
runCommandForced(
"--tld=tld",
"--client=NewRegistrar",
"--superuser",
"--reason=anchor-tenant-test",
"--contact=jd1234",
"--domain_name=example.tld",
"foo"));
} }
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--superuser", ParameterException.class,
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld"); () ->
runCommandForced(
"--superuser",
"--reason=anchor-tenant-test",
"--contact=jd1234",
"--domain_name=example.tld"));
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--foo=bar", "--client=NewRegistrar", "--superuser", ParameterException.class,
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld"); () ->
runCommandForced(
"--foo=bar",
"--client=NewRegistrar",
"--superuser",
"--reason=anchor-tenant-test",
"--contact=jd1234",
"--domain_name=example.tld"));
} }
@Test @Test
public void testFailure_missingDomainName() throws Exception { public void testFailure_missingDomainName() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--superuser", ParameterException.class,
"--reason=anchor-tenant-test", "--contact=jd1234", "foo"); () ->
runCommandForced(
"--client=NewRegistrar",
"--superuser",
"--reason=anchor-tenant-test",
"--contact=jd1234",
"foo"));
} }
@Test @Test
public void testFailure_missingContact() throws Exception { public void testFailure_missingContact() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--superuser", ParameterException.class,
"--reason=anchor-tenant-test", "--domain_name=example.tld", "foo"); () ->
runCommandForced(
"--client=NewRegistrar",
"--superuser",
"--reason=anchor-tenant-test",
"--domain_name=example.tld",
"foo"));
} }
@Test @Test
public void testFailure_notAsSuperuser() throws Exception { public void testFailure_notAsSuperuser() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommandForced("--client=NewRegistrar", IllegalArgumentException.class,
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld"); () ->
runCommandForced(
"--client=NewRegistrar",
"--reason=anchor-tenant-test",
"--contact=jd1234",
"--domain_name=example.tld"));
} }
} }

View file

@ -14,6 +14,8 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import google.registry.testing.DeterministicStringGenerator; import google.registry.testing.DeterministicStringGenerator;
import org.junit.Before; import org.junit.Before;
@ -58,30 +60,31 @@ public class CreateContactCommandTest extends EppToolCommandTestCase<CreateConta
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommandForced());
runCommandForced();
} }
@Test @Test
public void testFailure_tooManyStreetLines() throws Exception { public void testFailure_tooManyStreetLines() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommandForced( IllegalArgumentException.class,
"--client=NewRegistrar", () ->
"--street=\"123 Example Dr.\"", runCommandForced(
"--street=\"Floor 3\"", "--client=NewRegistrar",
"--street=\"Suite 100\"", "--street=\"123 Example Dr.\"",
"--street=\"Office 1\""); "--street=\"Floor 3\"",
"--street=\"Suite 100\"",
"--street=\"Office 1\""));
} }
@Test @Test
public void testFailure_badPhone() throws Exception { public void testFailure_badPhone() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--phone=3"); ParameterException.class, () -> runCommandForced("--client=NewRegistrar", "--phone=3"));
} }
@Test @Test
public void testFailure_badFax() throws Exception { public void testFailure_badFax() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--fax=3"); ParameterException.class, () -> runCommandForced("--client=NewRegistrar", "--fax=3"));
} }
} }

View file

@ -20,6 +20,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
@ -80,75 +81,96 @@ public class CreateCreditBalanceCommandTest extends CommandTestCase<CreateCredit
@Test @Test
public void testFailure_nonexistentParentRegistrar() throws Exception { public void testFailure_nonexistentParentRegistrar() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrar FakeRegistrar not found"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--registrar=FakeRegistrar", () ->
"--credit_id=" + creditId, runCommandForced(
"--balance=\"USD 100\"", "--registrar=FakeRegistrar",
"--effective_time=2014-11-01T01:02:03Z"); "--credit_id=" + creditId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("Registrar FakeRegistrar not found");
} }
@Test @Test
public void testFailure_nonexistentCreditId() throws Exception { public void testFailure_nonexistentCreditId() throws Exception {
long badId = creditId + 1; long badId = creditId + 1;
thrown.expect(NullPointerException.class); NullPointerException thrown =
thrown.expectMessage("ID " + badId); expectThrows(
runCommandForced( NullPointerException.class,
"--registrar=TheRegistrar", () ->
"--credit_id=" + badId, runCommandForced(
"--balance=\"USD 100\"", "--registrar=TheRegistrar",
"--effective_time=2014-11-01T01:02:03Z"); "--credit_id=" + badId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("ID " + badId);
} }
@Test @Test
public void testFailure_negativeBalance() throws Exception { public void testFailure_negativeBalance() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("negative"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--registrar=TheRegistrar", () ->
"--credit_id=" + creditId, runCommandForced(
"--balance=\"USD -1\"", "--registrar=TheRegistrar",
"--effective_time=2014-11-01T01:02:03Z"); "--credit_id=" + creditId,
"--balance=\"USD -1\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("negative");
} }
@Test @Test
public void testFailure_noRegistrar() throws Exception { public void testFailure_noRegistrar() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--registrar"); expectThrows(
runCommandForced( ParameterException.class,
"--credit_id=" + creditId, () ->
"--balance=\"USD 100\"", runCommandForced(
"--effective_time=2014-11-01T01:02:03Z"); "--credit_id=" + creditId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--registrar");
} }
@Test @Test
public void testFailure_noCreditId() throws Exception { public void testFailure_noCreditId() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--credit_id"); expectThrows(
runCommandForced( ParameterException.class,
"--registrar=TheRegistrar", () ->
"--balance=\"USD 100\"", runCommandForced(
"--effective_time=2014-11-01T01:02:03Z"); "--registrar=TheRegistrar",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--credit_id");
} }
@Test @Test
public void testFailure_noBalance() throws Exception { public void testFailure_noBalance() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--balance"); expectThrows(
runCommandForced( ParameterException.class,
"--registrar=TheRegistrar", () ->
"--credit_id=" + creditId, runCommandForced(
"--effective_time=2014-11-01T01:02:03Z"); "--registrar=TheRegistrar",
"--credit_id=" + creditId,
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--balance");
} }
@Test @Test
public void testFailure_noEffectiveTime() throws Exception { public void testFailure_noEffectiveTime() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--effective_time"); expectThrows(
runCommandForced( ParameterException.class,
"--registrar=TheRegistrar", () ->
"--credit_id=" + creditId, runCommandForced(
"--balance=\"USD 100\""); "--registrar=TheRegistrar",
"--credit_id=" + creditId,
"--balance=\"USD 100\""));
assertThat(thrown).hasMessageThat().contains("--effective_time");
} }
} }

View file

@ -19,6 +19,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
@ -93,104 +94,131 @@ public class CreateCreditCommandTest extends CommandTestCase<CreateCreditCommand
@Test @Test
public void testFailure_nonexistentParentRegistrar() throws Exception { public void testFailure_nonexistentParentRegistrar() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrar FakeRegistrar not found"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--registrar=FakeRegistrar", () ->
"--type=PROMOTION", runCommandForced(
"--tld=tld", "--registrar=FakeRegistrar",
"--balance=\"USD 100\"", "--type=PROMOTION",
"--effective_time=2014-11-01T01:02:03Z"); "--tld=tld",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("Registrar FakeRegistrar not found");
} }
@Test @Test
public void testFailure_nonexistentTld() throws Exception { public void testFailure_nonexistentTld() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("faketld"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--registrar=TheRegistrar", () ->
"--type=PROMOTION", runCommandForced(
"--tld=faketld", "--registrar=TheRegistrar",
"--balance=\"USD 100\"", "--type=PROMOTION",
"--effective_time=2014-11-01T01:02:03Z"); "--tld=faketld",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("faketld");
} }
@Test @Test
public void testFailure_nonexistentType() throws Exception { public void testFailure_nonexistentType() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("Invalid value for --type"); expectThrows(
runCommandForced( ParameterException.class,
"--registrar=TheRegistrar", () ->
"--type=BADTYPE", runCommandForced(
"--tld=tld", "--registrar=TheRegistrar",
"--balance=\"USD 100\"", "--type=BADTYPE",
"--effective_time=2014-11-01T01:02:03Z"); "--tld=tld",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("Invalid value for --type");
} }
@Test @Test
public void testFailure_negativeBalance() throws Exception { public void testFailure_negativeBalance() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("negative"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--registrar=TheRegistrar", () ->
"--type=PROMOTION", runCommandForced(
"--tld=tld", "--registrar=TheRegistrar",
"--balance=\"USD -1\"", "--type=PROMOTION",
"--effective_time=2014-11-01T01:02:03Z"); "--tld=tld",
"--balance=\"USD -1\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("negative");
} }
@Test @Test
public void testFailure_noRegistrar() throws Exception { public void testFailure_noRegistrar() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--registrar"); expectThrows(
runCommandForced( ParameterException.class,
"--type=PROMOTION", () ->
"--tld=tld", runCommandForced(
"--balance=\"USD 100\"", "--type=PROMOTION",
"--effective_time=2014-11-01T01:02:03Z"); "--tld=tld",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--registrar");
} }
@Test @Test
public void testFailure_noType() throws Exception { public void testFailure_noType() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--type"); expectThrows(
runCommandForced( ParameterException.class,
"--registrar=TheRegistrar", () ->
"--tld=tld", runCommandForced(
"--balance=\"USD 100\"", "--registrar=TheRegistrar",
"--effective_time=2014-11-01T01:02:03Z"); "--tld=tld",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--type");
} }
@Test @Test
public void testFailure_noTld() throws Exception { public void testFailure_noTld() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--tld"); expectThrows(
runCommandForced( ParameterException.class,
"--registrar=TheRegistrar", () ->
"--type=PROMOTION", runCommandForced(
"--balance=\"USD 100\"", "--registrar=TheRegistrar",
"--effective_time=2014-11-01T01:02:03Z"); "--type=PROMOTION",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--tld");
} }
@Test @Test
public void testFailure_noBalance() throws Exception { public void testFailure_noBalance() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--balance"); expectThrows(
runCommandForced( ParameterException.class,
"--registrar=TheRegistrar", () ->
"--type=PROMOTION", runCommandForced(
"--tld=tld", "--registrar=TheRegistrar",
"--effective_time=2014-11-01T01:02:03Z"); "--type=PROMOTION",
"--tld=tld",
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--balance");
} }
@Test @Test
public void testFailure_noEffectiveTime() throws Exception { public void testFailure_noEffectiveTime() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--effective_time"); expectThrows(
runCommandForced( ParameterException.class,
"--registrar=TheRegistrar", () ->
"--type=PROMOTION", runCommandForced(
"--tld=tld", "--registrar=TheRegistrar",
"--balance=\"USD 100\""); "--type=PROMOTION",
"--tld=tld",
"--balance=\"USD 100\""));
assertThat(thrown).hasMessageThat().contains("--effective_time");
} }
} }

View file

@ -14,6 +14,9 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import google.registry.testing.DeterministicStringGenerator; import google.registry.testing.DeterministicStringGenerator;
import org.junit.Before; import org.junit.Before;
@ -69,86 +72,122 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
@Test @Test
public void testFailure_duplicateDomains() throws Exception { public void testFailure_duplicateDomains() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Duplicate arguments found: \'example.tld\'"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--client=NewRegistrar", () ->
"--registrant=crr-admin", runCommandForced(
"--admins=crr-admin", "--client=NewRegistrar",
"--techs=crr-tech", "--registrant=crr-admin",
"example.tld", "--admins=crr-admin",
"example.tld"); "--techs=crr-tech",
"example.tld",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("Duplicate arguments found: \'example.tld\'");
} }
@Test @Test
public void testFailure_missingDomain() throws Exception { public void testFailure_missingDomain() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("Main parameters are required"); expectThrows(
runCommandForced( ParameterException.class,
"--client=NewRegistrar", () ->
"--registrant=crr-admin", runCommandForced(
"--admins=crr-admin", "--client=NewRegistrar",
"--techs=crr-tech"); "--registrant=crr-admin",
"--admins=crr-admin",
"--techs=crr-tech"));
assertThat(thrown).hasMessageThat().contains("Main parameters are required");
} }
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--client"); expectThrows(
runCommandForced( ParameterException.class,
"--admins=crr-admin", "--techs=crr-tech", "--registrant=crr-admin", "example.tld"); () ->
runCommandForced(
"--admins=crr-admin",
"--techs=crr-tech",
"--registrant=crr-admin",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("--client");
} }
@Test @Test
public void testFailure_missingRegistrant() throws Exception { public void testFailure_missingRegistrant() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrant must be specified"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--client=NewRegistrar", "--admins=crr-admin", "--techs=crr-tech", "example.tld"); () ->
runCommandForced(
"--client=NewRegistrar",
"--admins=crr-admin",
"--techs=crr-tech",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("Registrant must be specified");
} }
@Test @Test
public void testFailure_missingAdmins() throws Exception { public void testFailure_missingAdmins() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("At least one admin must be specified"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--client=NewRegistrar", "--registrant=crr-admin", "--techs=crr-tech", "example.tld"); () ->
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--techs=crr-tech",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("At least one admin must be specified");
} }
@Test @Test
public void testFailure_missingTechs() throws Exception { public void testFailure_missingTechs() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("At least one tech must be specified"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--client=NewRegistrar", "--registrant=crr-admin", "--admins=crr-admin", "example.tld"); () ->
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admins=crr-admin",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("At least one tech must be specified");
} }
@Test @Test
public void testFailure_tooManyNameServers() throws Exception { public void testFailure_tooManyNameServers() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("There can be at most 13 nameservers"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--client=NewRegistrar", () ->
"--registrant=crr-admin", runCommandForced(
"--admins=crr-admin", "--client=NewRegistrar",
"--techs=crr-tech", "--registrant=crr-admin",
"--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google," "--admins=crr-admin",
+ "ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google," "--techs=crr-tech",
+ "ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google," "--nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google,"
+ "ns13.zdns.google,ns14.zdns.google", + "ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google,"
"example.tld"); + "ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google,"
+ "ns13.zdns.google,ns14.zdns.google",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("There can be at most 13 nameservers");
} }
@Test @Test
public void testFailure_badPeriod() throws Exception { public void testFailure_badPeriod() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--period"); expectThrows(
runCommandForced( ParameterException.class,
"--client=NewRegistrar", () ->
"--registrant=crr-admin", runCommandForced(
"--admins=crr-admin", "--client=NewRegistrar",
"--techs=crr-tech", "--registrant=crr-admin",
"--period=x", "--admins=crr-admin",
"--domain=example.tld"); "--techs=crr-tech",
"--period=x",
"--domain=example.tld"));
assertThat(thrown).hasMessageThat().contains("--period");
} }
} }

View file

@ -14,7 +14,10 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.junit.Test; import org.junit.Test;
@ -43,18 +46,18 @@ public class CreateHostCommandTest extends EppToolCommandTestCase<CreateHostComm
@Test @Test
public void testFailure_missingHost() throws Exception { public void testFailure_missingHost() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommandForced("--client=NewRegistrar"));
runCommandForced("--client=NewRegistrar");
} }
@Test @Test
public void testFailure_invalidIpAddress() throws Exception { public void testFailure_invalidIpAddress() throws Exception {
createTld("tld"); createTld("tld");
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("'a.b.c.d' is not an IP string literal."); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--client=NewRegistrar", () ->
"--host=example.tld", runCommandForced(
"--addresses=a.b.c.d"); "--client=NewRegistrar", "--host=example.tld", "--addresses=a.b.c.d"));
assertThat(thrown).hasMessageThat().contains("'a.b.c.d' is not an IP string literal.");
} }
} }

View file

@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@ -226,45 +227,69 @@ public class CreateLrpTokensCommandTest extends CommandTestCase<CreateLrpTokensC
@Test @Test
public void testFailure_missingAssigneeOrFile() throws Exception { public void testFailure_missingAssigneeOrFile() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Exactly one of either assignee or filename must be specified."); expectThrows(IllegalArgumentException.class, () -> runCommand("--tlds=tld"));
runCommand("--tlds=tld"); assertThat(thrown)
.hasMessageThat()
.contains("Exactly one of either assignee or filename must be specified.");
} }
@Test @Test
public void testFailure_bothAssigneeAndFile() throws Exception { public void testFailure_bothAssigneeAndFile() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Exactly one of either assignee or filename must be specified."); expectThrows(
runCommand("--assignee=domain.tld", "--tlds=tld", "--input=" + assigneeFilePath); IllegalArgumentException.class,
() -> runCommand("--assignee=domain.tld", "--tlds=tld", "--input=" + assigneeFilePath));
assertThat(thrown)
.hasMessageThat()
.contains("Exactly one of either assignee or filename must be specified.");
} }
@Test @Test
public void testFailure_bothMetadataAndFile() throws Exception { public void testFailure_bothMetadataAndFile() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Metadata cannot be specified along with a filename."); expectThrows(
runCommand("--tlds=tld", "--input=" + assigneeFilePath, "--metadata=key=foo"); IllegalArgumentException.class,
() -> runCommand("--tlds=tld", "--input=" + assigneeFilePath, "--metadata=key=foo"));
assertThat(thrown)
.hasMessageThat()
.contains("Metadata cannot be specified along with a filename.");
} }
@Test @Test
public void testFailure_bothAssigneeAndMetadataColumns() throws Exception { public void testFailure_bothAssigneeAndMetadataColumns() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Metadata columns cannot be specified along with an assignee."); expectThrows(
runCommand("--assignee=domain.tld", "--tlds=tld", "--metadata_columns=foo=1"); IllegalArgumentException.class,
() -> runCommand("--assignee=domain.tld", "--tlds=tld", "--metadata_columns=foo=1"));
assertThat(thrown)
.hasMessageThat()
.contains("Metadata columns cannot be specified along with an assignee.");
} }
@Test @Test
public void testFailure_badTld() throws Exception { public void testFailure_badTld() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("TLDs do not exist: foo"); expectThrows(
runCommand("--assignee=domain.tld", "--tlds=foo"); IllegalArgumentException.class,
() -> runCommand("--assignee=domain.tld", "--tlds=foo"));
assertThat(thrown).hasMessageThat().contains("TLDs do not exist: foo");
} }
@Test @Test
public void testFailure_oneAssignee_byFile_insufficientMetadata() throws Exception { public void testFailure_oneAssignee_byFile_insufficientMetadata() throws Exception {
Files.asCharSink(assigneeFile, UTF_8).write("domain.tld,foo"); Files.asCharSink(assigneeFile, UTF_8).write("domain.tld,foo");
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Entry for domain.tld does not have a value for key2 (index 2)"); expectThrows(
runCommand("--input=" + assigneeFilePath, "--tlds=tld", "--metadata_columns=key=1,key2=2"); IllegalArgumentException.class,
() ->
runCommand(
"--input=" + assigneeFilePath,
"--tlds=tld",
"--metadata_columns=key=1,key2=2"));
assertThat(thrown)
.hasMessageThat()
.contains("Entry for domain.tld does not have a value for key2 (index 2)");
} }
private void assertLrpTokens(LrpTokenEntity... expected) throws Exception { private void assertLrpTokens(LrpTokenEntity... expected) throws Exception {

View file

@ -14,6 +14,7 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.ResourceUtils.readResourceUtf8; import static google.registry.util.ResourceUtils.readResourceUtf8;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
@ -50,17 +51,17 @@ public abstract class CreateOrUpdateReservedListCommandTestCase
@Test @Test
public void testFailure_fileDoesntExist() throws Exception { public void testFailure_fileDoesntExist() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced( ParameterException.class,
"--name=xn--q9jyb4c-blah", () ->
"--input=" + reservedTermsPath + "-nonexistent"); runCommandForced(
"--name=xn--q9jyb4c-blah", "--input=" + reservedTermsPath + "-nonexistent"));
} }
@Test @Test
public void testFailure_fileDoesntParse() throws Exception { public void testFailure_fileDoesntParse() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommandForced( IllegalArgumentException.class,
"--name=xn--q9jyb4c-blork", () -> runCommandForced("--name=xn--q9jyb4c-blork", "--input=" + invalidReservedTermsPath));
"--input=" + invalidReservedTermsPath);
} }
} }

View file

@ -14,7 +14,9 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.request.JsonResponse.JSON_SAFETY_PREFIX; import static google.registry.request.JsonResponse.JSON_SAFETY_PREFIX;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.ResourceUtils.readResourceUtf8; import static google.registry.util.ResourceUtils.readResourceUtf8;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyMapOf; import static org.mockito.Matchers.anyMapOf;
@ -92,16 +94,16 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
any(byte[].class))) any(byte[].class)))
.thenReturn( .thenReturn(
JSON_SAFETY_PREFIX + "{\"status\":\"error\",\"error\":\"foo already exists\"}"); JSON_SAFETY_PREFIX + "{\"status\":\"error\",\"error\":\"foo already exists\"}");
thrown.expect(VerifyException.class); VerifyException thrown =
thrown.expectMessage("Server error:"); expectThrows(
runCommandForced("-i=" + premiumTermsPath, "-n=foo"); VerifyException.class, () -> runCommandForced("-i=" + premiumTermsPath, "-n=foo"));
assertThat(thrown).hasMessageThat().contains("Server error:");
} }
@Test @Test
public void testRun_noInputFileSpecified_throwsException() throws Exception { public void testRun_noInputFileSpecified_throwsException() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown = expectThrows(ParameterException.class, () -> runCommand());
thrown.expectMessage("The following option is required"); assertThat(thrown).hasMessageThat().contains("The following option is required");
runCommand();
} }
@Test @Test
@ -110,8 +112,10 @@ public class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
"tmp_file2", "tmp_file2",
readResourceUtf8( readResourceUtf8(
CreatePremiumListCommandTest.class, "testdata/example_invalid_premium_terms.csv")); CreatePremiumListCommandTest.class, "testdata/example_invalid_premium_terms.csv"));
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Could not parse line in premium list"); expectThrows(
runCommandForced("-i=" + premiumTermsPath, "-n=foo"); IllegalArgumentException.class,
() -> runCommandForced("-i=" + premiumTermsPath, "-n=foo"));
assertThat(thrown).hasMessageThat().contains("Could not parse line in premium list");
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -14,6 +14,8 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
@ -54,9 +56,12 @@ public class CreateRegistrarGroupsCommandTest extends
@Test @Test
public void test_throwsExceptionForNonExistentRegistrar() throws Exception { public void test_throwsExceptionForNonExistentRegistrar() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage( expectThrows(
"Could not load registrar with id FakeRegistrarThatDefinitelyDoesNotExist"); IllegalArgumentException.class,
runCommandForced("FakeRegistrarThatDefinitelyDoesNotExist"); () -> runCommandForced("FakeRegistrarThatDefinitelyDoesNotExist"));
assertThat(thrown)
.hasMessageThat()
.contains("Could not load registrar with id FakeRegistrarThatDefinitelyDoesNotExist");
} }
} }

View file

@ -21,6 +21,7 @@ import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED
import static google.registry.testing.DatastoreHelper.createTlds; import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.tools.CreateReservedListCommand.INVALID_FORMAT_ERROR_MESSAGE; import static google.registry.tools.CreateReservedListCommand.INVALID_FORMAT_ERROR_MESSAGE;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
@ -90,9 +91,11 @@ public class CreateReservedListCommandTest extends
public void testFailure_reservedListWithThatNameAlreadyExists() throws Exception { public void testFailure_reservedListWithThatNameAlreadyExists() throws Exception {
ReservedList rl = persistReservedList("xn--q9jyb4c_foo", "jones,FULLY_BLOCKED"); ReservedList rl = persistReservedList("xn--q9jyb4c_foo", "jones,FULLY_BLOCKED");
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setReservedLists(rl).build()); persistResource(Registry.get("xn--q9jyb4c").asBuilder().setReservedLists(rl).build());
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("A reserved list already exists by this name"); expectThrows(
runCommandForced("--name=xn--q9jyb4c_foo", "--input=" + reservedTermsPath); IllegalArgumentException.class,
() -> runCommandForced("--name=xn--q9jyb4c_foo", "--input=" + reservedTermsPath));
assertThat(thrown).hasMessageThat().contains("A reserved list already exists by this name");
} }
@Test @Test

View file

@ -78,16 +78,24 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test @Test
public void testFailure_multipleArguments() throws Exception { public void testFailure_multipleArguments() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Can't create more than one TLD at a time"); expectThrows(
runCommandForced("--roid_suffix=BLAH", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c", "test"); IllegalArgumentException.class,
() ->
runCommandForced(
"--roid_suffix=BLAH", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c", "test"));
assertThat(thrown).hasMessageThat().contains("Can't create more than one TLD at a time");
} }
@Test @Test
public void testFailure_multipleDuplicateArguments() throws Exception { public void testFailure_multipleDuplicateArguments() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Can't create more than one TLD at a time"); expectThrows(
runCommandForced("--roid_suffix=BLAH", "--dns_writers=VoidDnsWriter", "test", "test"); IllegalArgumentException.class,
() ->
runCommandForced(
"--roid_suffix=BLAH", "--dns_writers=VoidDnsWriter", "test", "test"));
assertThat(thrown).hasMessageThat().contains("Can't create more than one TLD at a time");
} }
@Test @Test
@ -303,13 +311,16 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test @Test
public void testFailure_invalidAddGracePeriod() throws Exception { public void testFailure_invalidAddGracePeriod() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Invalid format: \"5m\""); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--add_grace_period=5m", () ->
"--roid_suffix=Q9JYB4C", runCommandForced(
"--dns_writers=VoidDnsWriter", "--add_grace_period=5m",
"xn--q9jyb4c"); "--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\"");
} }
@Test @Test
@ -327,101 +338,131 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test @Test
public void testFailure_invalidRedemptionGracePeriod() throws Exception { public void testFailure_invalidRedemptionGracePeriod() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Invalid format: \"5m\""); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--redemption_grace_period=5m", () ->
"--roid_suffix=Q9JYB4C", runCommandForced(
"--dns_writers=VoidDnsWriter", "--redemption_grace_period=5m",
"xn--q9jyb4c"); "--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\"");
} }
@Test @Test
public void testFailure_invalidPendingDeleteLength() throws Exception { public void testFailure_invalidPendingDeleteLength() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Invalid format: \"5m\""); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--pending_delete_length=5m", () ->
"--roid_suffix=Q9JYB4C", runCommandForced(
"--dns_writers=VoidDnsWriter", "--pending_delete_length=5m",
"xn--q9jyb4c"); "--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\"");
} }
@Test @Test
public void testFailure_invalidTldState() throws Exception { public void testFailure_invalidTldState() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("Invalid value for --initial_tld_state parameter"); expectThrows(
runCommandForced( ParameterException.class,
"--initial_tld_state=INVALID_STATE", () ->
"--roid_suffix=Q9JYB4C", runCommandForced(
"--dns_writers=VoidDnsWriter", "--initial_tld_state=INVALID_STATE",
"xn--q9jyb4c"); "--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Invalid value for --initial_tld_state parameter");
} }
@Test @Test
public void testFailure_bothTldStateFlags() throws Exception { public void testFailure_bothTldStateFlags() throws Exception {
DateTime now = DateTime.now(UTC); DateTime now = DateTime.now(UTC);
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Don't pass both --initial_tld_state and --tld_state_transitions"); expectThrows(
runCommandForced( IllegalArgumentException.class,
String.format( () ->
"--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", runCommandForced(
now, now.plus(Duration.millis(1))), String.format(
"--initial_tld_state=GENERAL_AVAILABILITY", "--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE",
"--dns_writers=VoidDnsWriter", now, now.plus(Duration.millis(1))),
"xn--q9jyb4c"); "--initial_tld_state=GENERAL_AVAILABILITY",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("Don't pass both --initial_tld_state and --tld_state_transitions");
} }
@Test @Test
public void testFailure_negativeInitialRenewBillingCost() throws Exception { public void testFailure_negativeInitialRenewBillingCost() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Renew billing cost cannot be negative"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--initial_renew_billing_cost=USD -42", () ->
"--roid_suffix=Q9JYB4C", runCommandForced(
"--dns_writers=VoidDnsWriter", "--initial_renew_billing_cost=USD -42",
"xn--q9jyb4c"); "--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Renew billing cost cannot be negative");
} }
@Test @Test
public void testFailure_invalidEapCurrency() throws Exception { public void testFailure_invalidEapCurrency() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("All EAP fees must be in the registry's currency"); expectThrows(
runCommandForced( IllegalArgumentException.class,
String.format( () ->
"--eap_fee_schedule=\"%s=JPY 123456\"", START_OF_TIME.toString(DATETIME_FORMAT)), runCommandForced(
"--roid_suffix=Q9JYB4C", String.format(
"--dns_writers=VoidDnsWriter", "--eap_fee_schedule=\"%s=JPY 123456\"",
"xn--q9jyb4c"); START_OF_TIME.toString(DATETIME_FORMAT)),
"--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("All EAP fees must be in the registry's currency");
} }
@Test @Test
public void testFailure_noTldName() throws Exception { public void testFailure_noTldName() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown = expectThrows(ParameterException.class, () -> runCommandForced());
thrown.expectMessage("Main parameters are required (\"Names of the TLDs\")"); assertThat(thrown)
runCommandForced(); .hasMessageThat()
.contains("Main parameters are required (\"Names of the TLDs\")");
} }
@Test @Test
public void testFailure_noDnsWriter() throws Exception { public void testFailure_noDnsWriter() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("At least one DNS writer must be specified"); expectThrows(
runCommandForced("xn--q9jyb4c", "--roid_suffix=Q9JYB4C"); IllegalArgumentException.class,
() -> runCommandForced("xn--q9jyb4c", "--roid_suffix=Q9JYB4C"));
assertThat(thrown).hasMessageThat().contains("At least one DNS writer must be specified");
} }
@Test @Test
public void testFailure_alreadyExists() throws Exception { public void testFailure_alreadyExists() throws Exception {
createTld("xn--q9jyb4c"); createTld("xn--q9jyb4c");
thrown.expect(IllegalStateException.class); IllegalStateException thrown =
thrown.expectMessage("TLD 'xn--q9jyb4c' already exists"); expectThrows(
runCommandForced("--roid_suffix=NOTDUPE", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c"); IllegalStateException.class,
() ->
runCommandForced(
"--roid_suffix=NOTDUPE", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("TLD 'xn--q9jyb4c' already exists");
} }
@Test @Test
public void testFailure_tldStartsWithDigit() throws Exception { public void testFailure_tldStartsWithDigit() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("TLDs cannot begin with a number"); expectThrows(
runCommandForced("1foo", "--roid_suffix=1FOO", "--dns_writers=VoidDnsWriter"); IllegalArgumentException.class,
() -> runCommandForced("1foo", "--roid_suffix=1FOO", "--dns_writers=VoidDnsWriter"));
assertThat(thrown).hasMessageThat().contains("TLDs cannot begin with a number");
} }
@Test @Test
@ -556,43 +597,60 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test @Test
public void testFailure_setPremiumListThatDoesntExist() throws Exception { public void testFailure_setPremiumListThatDoesntExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("The premium list 'phonies' doesn't exist"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--premium_list=phonies", () ->
"--roid_suffix=Q9JYB4C", runCommandForced(
"--dns_writers=VoidDnsWriter", "--premium_list=phonies",
"xn--q9jyb4c"); "--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("The premium list 'phonies' doesn't exist");
} }
@Test @Test
public void testFailure_addLrpPeriod_backwardsInterval() throws Exception { public void testFailure_addLrpPeriod_backwardsInterval() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage( expectThrows(
"--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z not an ISO-8601 interval"); ParameterException.class,
runCommandForced( () ->
"--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z", runCommandForced(
"--roid_suffix=Q9JYB4C", "--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z",
"--dns_writers=VoidDnsWriter", "--roid_suffix=Q9JYB4C",
"xn--q9jyb4c"); "--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains(
"--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z not an ISO-8601 interval");
} }
@Test @Test
public void testFailure_addLrpPeriod_badInterval() throws Exception { public void testFailure_addLrpPeriod_badInterval() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--lrp_period=foobar not an ISO-8601 interval"); expectThrows(
runCommandForced( ParameterException.class,
"--lrp_period=foobar", () ->
"--roid_suffix=Q9JYB4C", runCommandForced(
"--dns_writers=VoidDnsWriter", "--lrp_period=foobar",
"xn--q9jyb4c"); "--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("--lrp_period=foobar not an ISO-8601 interval");
} }
@Test @Test
public void testFailure_specifiedDnsWriters_dontExist() throws Exception { public void testFailure_specifiedDnsWriters_dontExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Invalid DNS writer name(s) specified: [Deadbeef, Invalid]"); expectThrows(
runCommandForced("xn--q9jyb4c", "--roid_suffix=Q9JYB4C", "--dns_writers=Invalid,Deadbeef"); IllegalArgumentException.class,
() ->
runCommandForced(
"xn--q9jyb4c", "--roid_suffix=Q9JYB4C", "--dns_writers=Invalid,Deadbeef"));
assertThat(thrown)
.hasMessageThat()
.contains("Invalid DNS writer name(s) specified: [Deadbeef, Invalid]");
} }
private void runSuccessfulReservedListsTest(String reservedLists) throws Exception { private void runSuccessfulReservedListsTest(String reservedLists) throws Exception {

View file

@ -20,6 +20,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.money.CurrencyUnit.USD; import static org.joda.money.CurrencyUnit.USD;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
@ -111,30 +112,34 @@ public class DeleteCreditCommandTest extends CommandTestCase<DeleteCreditCommand
@Test @Test
public void testFailure_nonexistentParentRegistrar() throws Exception { public void testFailure_nonexistentParentRegistrar() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrar FakeRegistrar not found"); expectThrows(
runCommandForced("--registrar=FakeRegistrar", "--credit_id=" + creditAId); IllegalArgumentException.class,
() -> runCommandForced("--registrar=FakeRegistrar", "--credit_id=" + creditAId));
assertThat(thrown).hasMessageThat().contains("Registrar FakeRegistrar not found");
} }
@Test @Test
public void testFailure_nonexistentCreditId() throws Exception { public void testFailure_nonexistentCreditId() throws Exception {
long badId = creditAId + creditBId + 1; long badId = creditAId + creditBId + 1;
thrown.expect(NullPointerException.class); NullPointerException thrown =
thrown.expectMessage("ID " + badId); expectThrows(
runCommandForced("--registrar=TheRegistrar", "--credit_id=" + badId); NullPointerException.class,
() -> runCommandForced("--registrar=TheRegistrar", "--credit_id=" + badId));
assertThat(thrown).hasMessageThat().contains("ID " + badId);
} }
@Test @Test
public void testFailure_noRegistrar() throws Exception { public void testFailure_noRegistrar() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--registrar"); expectThrows(ParameterException.class, () -> runCommandForced("--credit_id=" + creditAId));
runCommandForced("--credit_id=" + creditAId); assertThat(thrown).hasMessageThat().contains("--registrar");
} }
@Test @Test
public void testFailure_noCreditId() throws Exception { public void testFailure_noCreditId() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--credit_id"); expectThrows(ParameterException.class, () -> runCommandForced("--registrar=TheRegistrar"));
runCommandForced("--registrar=TheRegistrar"); assertThat(thrown).hasMessageThat().contains("--credit_id");
} }
} }

View file

@ -14,6 +14,8 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.junit.Test; import org.junit.Test;
@ -57,33 +59,48 @@ public class DeleteDomainCommandTest extends EppToolCommandTestCase<DeleteDomain
@Test @Test
public void testFailure_noReason() throws Exception { public void testFailure_noReason() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--client=NewRegistrar", "--domain_name=example.tld", "--force"); ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--domain_name=example.tld", "--force"));
} }
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--domain_name=example.tld", "--force", "--reason=Test"); ParameterException.class,
() -> runCommand("--domain_name=example.tld", "--force", "--reason=Test"));
} }
@Test @Test
public void testFailure_missingDomainName() throws Exception { public void testFailure_missingDomainName() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--client=NewRegistrar", "--force", "--reason=Test"); ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--force", "--reason=Test"));
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand( ParameterException.class,
"--client=NewRegistrar", "--domain_name=example.tld", "--force", "--reason=Test", "--foo"); () ->
runCommand(
"--client=NewRegistrar",
"--domain_name=example.tld",
"--force",
"--reason=Test",
"--foo"));
} }
@Test @Test
public void testFailure_mainParameter() throws Exception { public void testFailure_mainParameter() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand( ParameterException.class,
"--client=NewRegistrar", "--domain_name=example.tld", "--force", "--reason=Test", "foo"); () ->
runCommand(
"--client=NewRegistrar",
"--domain_name=example.tld",
"--force",
"--reason=Test",
"foo"));
} }
} }

View file

@ -14,6 +14,8 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.junit.Test; import org.junit.Test;
@ -57,33 +59,48 @@ public class DeleteHostCommandTest extends EppToolCommandTestCase<DeleteHostComm
@Test @Test
public void testFailure_noReason() throws Exception { public void testFailure_noReason() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--client=NewRegistrar", "--host=ns1.example.tld", "--force"); ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--host=ns1.example.tld", "--force"));
} }
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--host=ns1.example.tld", "--force", "--reason=Test"); ParameterException.class,
() -> runCommand("--host=ns1.example.tld", "--force", "--reason=Test"));
} }
@Test @Test
public void testFailure_missingHostName() throws Exception { public void testFailure_missingHostName() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--client=NewRegistrar", "--force", "--reason=Test"); ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--force", "--reason=Test"));
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand( ParameterException.class,
"--client=NewRegistrar", "--host=ns1.example.tld", "--force", "--reason=Test", "--foo"); () ->
runCommand(
"--client=NewRegistrar",
"--host=ns1.example.tld",
"--force",
"--reason=Test",
"--foo"));
} }
@Test @Test
public void testFailure_mainParameter() throws Exception { public void testFailure_mainParameter() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand( ParameterException.class,
"--client=NewRegistrar", "--host=ns1.example.tld", "--force", "--reason=Test", "foo"); () ->
runCommand(
"--client=NewRegistrar",
"--host=ns1.example.tld",
"--force",
"--reason=Test",
"foo"));
} }
} }

View file

@ -22,6 +22,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadPremiumListEntries; import static google.registry.testing.DatastoreHelper.loadPremiumListEntries;
import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.label.PremiumList; import google.registry.model.registry.label.PremiumList;
@ -48,9 +49,11 @@ public class DeletePremiumListCommandTest extends CommandTestCase<DeletePremiumL
@Test @Test
public void testFailure_whenPremiumListDoesNotExist() throws Exception { public void testFailure_whenPremiumListDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Cannot delete the premium list foo because it doesn't exist."); expectThrows(IllegalArgumentException.class, () -> runCommandForced("--name=foo"));
runCommandForced("--name=foo"); assertThat(thrown)
.hasMessageThat()
.contains("Cannot delete the premium list foo because it doesn't exist.");
} }
@Test @Test

View file

@ -20,6 +20,7 @@ import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistReservedList; import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.label.ReservedList; import google.registry.model.registry.label.ReservedList;
@ -47,9 +48,11 @@ public class DeleteReservedListCommandTest extends CommandTestCase<DeleteReserve
public void testFailure_whenReservedListDoesNotExist() throws Exception { public void testFailure_whenReservedListDoesNotExist() throws Exception {
String expectedError = String expectedError =
"Cannot delete the reserved list doesntExistReservedList because it doesn't exist."; "Cannot delete the reserved list doesntExistReservedList because it doesn't exist.";
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage(expectedError); expectThrows(
runCommandForced("--name=doesntExistReservedList"); IllegalArgumentException.class,
() -> runCommandForced("--name=doesntExistReservedList"));
assertThat(thrown).hasMessageThat().contains(expectedError);
} }
@Test @Test

View file

@ -18,6 +18,7 @@ import static google.registry.testing.DatastoreHelper.allowRegistrarAccess;
import static google.registry.testing.DatastoreHelper.newRegistry; import static google.registry.testing.DatastoreHelper.newRegistry;
import static google.registry.testing.DatastoreHelper.persistDeletedDomain; import static google.registry.testing.DatastoreHelper.persistDeletedDomain;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.base.Ascii; import com.google.common.base.Ascii;
@ -57,35 +58,30 @@ public class DeleteTldCommandTest extends CommandTestCase<DeleteTldCommand> {
runCommandForced("--tld=" + TLD_TEST); runCommandForced("--tld=" + TLD_TEST);
Registry.get(TLD_REAL); Registry.get(TLD_REAL);
thrown.expect(RegistryNotFoundException.class); assertThrows(RegistryNotFoundException.class, () -> Registry.get(TLD_TEST));
Registry.get(TLD_TEST);
} }
@Test @Test
public void testFailure_whenTldDoesNotExist() throws Exception { public void testFailure_whenTldDoesNotExist() throws Exception {
thrown.expect(RegistryNotFoundException.class); assertThrows(RegistryNotFoundException.class, () -> runCommandForced("--tld=nonexistenttld"));
runCommandForced("--tld=nonexistenttld");
} }
@Test @Test
public void testFailure_whenTldIsReal() throws Exception { public void testFailure_whenTldIsReal() throws Exception {
thrown.expect(IllegalStateException.class); assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_REAL));
runCommandForced("--tld=" + TLD_REAL);
} }
@Test @Test
public void testFailure_whenDomainsArePresent() throws Exception { public void testFailure_whenDomainsArePresent() throws Exception {
persistDeletedDomain("domain." + TLD_TEST, DateTime.parse("2000-01-01TZ")); persistDeletedDomain("domain." + TLD_TEST, DateTime.parse("2000-01-01TZ"));
thrown.expect(IllegalStateException.class); assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_TEST));
runCommandForced("--tld=" + TLD_TEST);
} }
@Test @Test
public void testFailure_whenRegistrarLinksToTld() throws Exception { public void testFailure_whenRegistrarLinksToTld() throws Exception {
allowRegistrarAccess("TheRegistrar", TLD_TEST); allowRegistrarAccess("TheRegistrar", TLD_TEST);
thrown.expect(IllegalStateException.class); assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_TEST));
runCommandForced("--tld=" + TLD_TEST);
} }
} }

View file

@ -14,6 +14,8 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.junit.Test; import org.junit.Test;
@ -38,41 +40,62 @@ public class DomainApplicationInfoCommandTest
@Test @Test
public void testFailure_invalidPhase() throws Exception { public void testFailure_invalidPhase() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", IllegalArgumentException.class,
"--phase=landrise", "--id=123"); () ->
runCommandForced(
"--client=NewRegistrar",
"--domain_name=example.tld",
"--phase=landrise",
"--id=123"));
} }
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--domain_name=example.tld", "--phase=sunrush", "--id=123"); ParameterException.class,
() -> runCommandForced("--domain_name=example.tld", "--phase=sunrush", "--id=123"));
} }
@Test @Test
public void testFailure_missingPhase() throws Exception { public void testFailure_missingPhase() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", "--id=123"); ParameterException.class,
() -> runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", "--id=123"));
} }
@Test @Test
public void testFailure_missingApplicationId() throws Exception { public void testFailure_missingApplicationId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", ParameterException.class,
"--phase=landrush"); () ->
runCommandForced(
"--client=NewRegistrar", "--domain_name=example.tld", "--phase=landrush"));
} }
@Test @Test
public void testFailure_mainParameter() throws Exception { public void testFailure_mainParameter() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", ParameterException.class,
"--phase=landrush", "--id=123", "foo"); () ->
runCommandForced(
"--client=NewRegistrar",
"--domain_name=example.tld",
"--phase=landrush",
"--id=123",
"foo"));
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", ParameterException.class,
"--phase=landrush", "--id=123", "--foo=bar"); () ->
runCommandForced(
"--client=NewRegistrar",
"--domain_name=example.tld",
"--phase=landrush",
"--id=123",
"--foo=bar"));
} }
} }

View file

@ -14,6 +14,8 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.junit.Test; import org.junit.Test;
@ -59,19 +61,18 @@ public class DomainCheckClaimsCommandTest extends EppToolCommandTestCase<DomainC
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommandForced("example.tld"));
runCommandForced("example.tld");
} }
@Test @Test
public void testFailure_NoMainParameter() throws Exception { public void testFailure_NoMainParameter() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommandForced("--client=NewRegistrar"));
runCommandForced("--client=NewRegistrar");
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld"); ParameterException.class,
() -> runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld"));
} }
} }

View file

@ -14,6 +14,8 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.junit.Test; import org.junit.Test;
@ -59,19 +61,18 @@ public class DomainCheckCommandTest extends EppToolCommandTestCase<DomainCheckCo
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommandForced("example.tld"));
runCommandForced("example.tld");
} }
@Test @Test
public void testFailure_NoMainParameter() throws Exception { public void testFailure_NoMainParameter() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommandForced("--client=NewRegistrar"));
runCommandForced("--client=NewRegistrar");
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld"); ParameterException.class,
() -> runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld"));
} }
} }

View file

@ -14,6 +14,8 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.junit.Test; import org.junit.Test;
@ -59,19 +61,18 @@ public class DomainCheckFeeCommandTest extends EppToolCommandTestCase<DomainChec
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommandForced("example.tld"));
runCommandForced("example.tld");
} }
@Test @Test
public void testFailure_NoMainParameter() throws Exception { public void testFailure_NoMainParameter() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommandForced("--client=NewRegistrar"));
runCommandForced("--client=NewRegistrar");
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld"); ParameterException.class,
() -> runCommandForced("--client=NewRegistrar", "--unrecognized=foo", "example.tld"));
} }
} }

View file

@ -14,6 +14,9 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import google.registry.tools.server.ToolsTestData; import google.registry.tools.server.ToolsTestData;
@ -71,8 +74,10 @@ public class EppToolCommandTest extends EppToolCommandTestCase<EppToolCommand> {
@Test @Test
public void testFailure_nonexistentClientId() throws Exception { public void testFailure_nonexistentClientId() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("fakeclient"); expectThrows(
runCommandForced("--client=fakeclient", "fake-xml"); IllegalArgumentException.class,
() -> runCommandForced("--client=fakeclient", "fake-xml"));
assertThat(thrown).hasMessageThat().contains("fakeclient");
} }
} }

View file

@ -14,6 +14,7 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
@ -77,19 +78,20 @@ public class ExecuteEppCommandTest extends EppToolCommandTestCase<ExecuteEppComm
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand("--force", "foo.xml"));
runCommand("--force", "foo.xml");
} }
@Test @Test
public void testFailure_forceAndDryRunIncompatible() throws Exception { public void testFailure_forceAndDryRunIncompatible() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--client=NewRegistrar", "--force", "--dry_run", eppFile); IllegalArgumentException.class,
() -> runCommand("--client=NewRegistrar", "--force", "--dry_run", eppFile));
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--client=NewRegistrar", "--unrecognized=foo", "--force", "foo.xml"); ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--unrecognized=foo", "--force", "foo.xml"));
} }
} }

View file

@ -20,6 +20,7 @@ import static google.registry.testing.DatastoreHelper.newContactResourceWithRoid
import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.newDomainApplication;
import static google.registry.testing.DatastoreHelper.newSunriseApplication; import static google.registry.testing.DatastoreHelper.newSunriseApplication;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
@ -320,19 +321,16 @@ public class GenerateAuctionDataCommandTest extends CommandTestCase<GenerateAuct
@Test @Test
public void testFailure_missingTldName() throws Exception { public void testFailure_missingTldName() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand());
runCommand();
} }
@Test @Test
public void testFailure_tooManyParameters() throws Exception { public void testFailure_tooManyParameters() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("xn--q9jyb4c", "foobar"));
runCommand("xn--q9jyb4c", "foobar");
} }
@Test @Test
public void testFailure_nonexistentTld() throws Exception { public void testFailure_nonexistentTld() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("foobarbaz"));
runCommand("foobarbaz");
} }
} }

View file

@ -22,6 +22,7 @@ import static google.registry.testing.DatastoreHelper.newHostResource;
import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
@ -203,13 +204,11 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
@Test @Test
public void testFailure_tldDoesNotExist() throws Exception { public void testFailure_tldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--tld=foobar"));
runCommand("--tld=foobar");
} }
@Test @Test
public void testFailure_missingTldParameter() throws Exception { public void testFailure_missingTldParameter() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand(""));
runCommand("");
} }
} }

View file

@ -15,7 +15,9 @@
package google.registry.tools; package google.registry.tools;
import static com.google.appengine.api.taskqueue.QueueFactory.getQueue; import static com.google.appengine.api.taskqueue.QueueFactory.getQueue;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -51,89 +53,135 @@ public class GenerateEscrowDepositCommandTest
@Test @Test
public void testCommand_missingTld() throws Exception { public void testCommand_missingTld() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("The following option is required: -t, --tld"); expectThrows(
runCommand("--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42", "-o test"); ParameterException.class,
() ->
runCommand("--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42", "-o test"));
assertThat(thrown).hasMessageThat().contains("The following option is required: -t, --tld");
} }
@Test @Test
public void testCommand_emptyTld() throws Exception { public void testCommand_emptyTld() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Null or empty TLD specified"); expectThrows(
runCommand("--tld=", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42", "-o test"); IllegalArgumentException.class,
() ->
runCommand(
"--tld=",
"--watermark=2017-01-01T00:00:00Z",
"--mode=thin",
"-r 42",
"-o test"));
assertThat(thrown).hasMessageThat().contains("Null or empty TLD specified");
} }
@Test @Test
public void testCommand_invalidTld() throws Exception { public void testCommand_invalidTld() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("TLDs do not exist: invalid"); expectThrows(
runCommand( IllegalArgumentException.class,
"--tld=invalid", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42", "-o test"); () ->
runCommand(
"--tld=invalid",
"--watermark=2017-01-01T00:00:00Z",
"--mode=thin",
"-r 42",
"-o test"));
assertThat(thrown).hasMessageThat().contains("TLDs do not exist: invalid");
} }
@Test @Test
public void testCommand_missingWatermark() throws Exception { public void testCommand_missingWatermark() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("The following option is required: -w, --watermark"); expectThrows(
runCommand("--tld=tld", "--mode=full", "-r 42", "-o test"); ParameterException.class,
() -> runCommand("--tld=tld", "--mode=full", "-r 42", "-o test"));
assertThat(thrown)
.hasMessageThat()
.contains("The following option is required: -w, --watermark");
} }
@Test @Test
public void testCommand_emptyWatermark() throws Exception { public void testCommand_emptyWatermark() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Invalid format: \"\""); expectThrows(
runCommand("--tld=tld", "--watermark=", "--mode=full", "-r 42", "-o test"); IllegalArgumentException.class,
() -> runCommand("--tld=tld", "--watermark=", "--mode=full", "-r 42", "-o test"));
assertThat(thrown).hasMessageThat().contains("Invalid format: \"\"");
} }
@Test @Test
public void testCommand_missingOutdir() throws Exception { public void testCommand_missingOutdir() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("The following option is required: -o, --outdir"); expectThrows(
runCommand("--tld=tld", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42"); ParameterException.class,
() ->
runCommand(
"--tld=tld", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "-r 42"));
assertThat(thrown).hasMessageThat().contains("The following option is required: -o, --outdir");
} }
@Test @Test
public void testCommand_emptyOutdir() throws Exception { public void testCommand_emptyOutdir() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("Output subdirectory must not be empty"); expectThrows(
runCommand( ParameterException.class,
"--tld=tld", "--watermark=2017-01-01T00:00:00Z", "--mode=thin", "--outdir=", "-r 42"); () ->
runCommand(
"--tld=tld",
"--watermark=2017-01-01T00:00:00Z",
"--mode=thin",
"--outdir=",
"-r 42"));
assertThat(thrown).hasMessageThat().contains("Output subdirectory must not be empty");
} }
@Test @Test
public void testCommand_invalidWatermark() throws Exception { public void testCommand_invalidWatermark() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("Each watermark date must be the start of a day"); expectThrows(
runCommand( ParameterException.class,
"--tld=tld", () ->
"--watermark=2017-01-01T10:00:00Z,2017-01-02T00:00:00Z", runCommand(
"--mode=thin", "--tld=tld",
"-r 42", "--watermark=2017-01-01T10:00:00Z,2017-01-02T00:00:00Z",
"-o test"); "--mode=thin",
"-r 42",
"-o test"));
assertThat(thrown).hasMessageThat().contains("Each watermark date must be the start of a day");
} }
@Test @Test
public void testCommand_invalidMode() throws Exception { public void testCommand_invalidMode() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("Invalid value for -m parameter. Allowed values:[FULL, THIN]"); expectThrows(
runCommand( ParameterException.class,
"--tld=tld", () ->
"--watermark=2017-01-01T00:00:00Z", runCommand(
"--mode=thing", "--tld=tld",
"-r 42", "--watermark=2017-01-01T00:00:00Z",
"-o test"); "--mode=thing",
"-r 42",
"-o test"));
assertThat(thrown)
.hasMessageThat()
.contains("Invalid value for -m parameter. Allowed values:[FULL, THIN]");
} }
@Test @Test
public void testCommand_invalidRevision() throws Exception { public void testCommand_invalidRevision() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("Revision must be greater than or equal to zero"); expectThrows(
runCommand( ParameterException.class,
"--tld=tld", () ->
"--watermark=2017-01-01T00:00:00Z", runCommand(
"--mode=thin", "--tld=tld",
"-r -1", "--watermark=2017-01-01T00:00:00Z",
"-o test"); "--mode=thin",
"-r -1",
"-o test"));
assertThat(thrown).hasMessageThat().contains("Revision must be greater than or equal to zero");
} }
@Test @Test

View file

@ -19,6 +19,7 @@ import static google.registry.testing.DatastoreHelper.newDomainApplication;
import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication; import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication;
import static google.registry.testing.DatastoreHelper.persistDeletedDomainApplication; import static google.registry.testing.DatastoreHelper.persistDeletedDomainApplication;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
@ -87,8 +88,7 @@ public class GetApplicationCommandTest extends CommandTestCase<GetApplicationCom
@Test @Test
public void testFailure_noApplicationId() throws Exception { public void testFailure_noApplicationId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand());
runCommand();
} }
@Test @Test

View file

@ -14,10 +14,13 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.newDomainApplication;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
@ -60,9 +63,9 @@ public class GetApplicationIdsCommandTest extends CommandTestCase<GetApplication
@Test @Test
public void testFailure_tldDoesNotExist() throws Exception { public void testFailure_tldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Domain name is not under a recognized TLD"); expectThrows(IllegalArgumentException.class, () -> runCommand("example.foo"));
runCommand("example.foo"); assertThat(thrown).hasMessageThat().contains("Domain name is not under a recognized TLD");
} }
@Test @Test
@ -75,8 +78,7 @@ public class GetApplicationIdsCommandTest extends CommandTestCase<GetApplication
@Test @Test
public void testFailure_noDomainName() throws Exception { public void testFailure_noDomainName() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand());
runCommand();
} }
private void persistDomainApplication(String domainName, String repoId) { private void persistDomainApplication(String domainName, String repoId) {

View file

@ -19,6 +19,7 @@ import static google.registry.testing.DatastoreHelper.newContactResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
@ -79,8 +80,7 @@ public class GetContactCommandTest extends CommandTestCase<GetContactCommand> {
@Test @Test
public void testFailure_noContact() throws Exception { public void testFailure_noContact() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand());
runCommand();
} }
@Test @Test

View file

@ -19,6 +19,7 @@ import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistDeletedDomain; import static google.registry.testing.DatastoreHelper.persistDeletedDomain;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
@ -95,8 +96,7 @@ public class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
@Test @Test
public void testFailure_noDomainName() throws Exception { public void testFailure_noDomainName() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand());
runCommand();
} }
@Test @Test

View file

@ -19,6 +19,7 @@ import static google.registry.testing.DatastoreHelper.newHostResource;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
@ -106,7 +107,6 @@ public class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
@Test @Test
public void testFailure_noHostName() throws Exception { public void testFailure_noHostName() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand());
runCommand();
} }
} }

View file

@ -14,9 +14,11 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication; import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainApplication; import google.registry.model.domain.DomainApplication;
@ -79,8 +81,10 @@ public class GetLrpTokenCommandTest extends CommandTestCase<GetLrpTokenCommand>
@Test @Test
public void testFailure_noArgs() throws Exception { public void testFailure_noArgs() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Exactly one of either token or assignee must be specified."); expectThrows(IllegalArgumentException.class, () -> runCommand());
runCommand(); assertThat(thrown)
.hasMessageThat()
.contains("Exactly one of either token or assignee must be specified.");
} }
} }

View file

@ -14,6 +14,10 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.junit.Test; import org.junit.Test;
@ -34,21 +38,20 @@ public class GetRegistrarCommandTest extends CommandTestCase<GetRegistrarCommand
@Test @Test
public void testFailure_registrarDoesNotExist() throws Exception { public void testFailure_registrarDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrar with id ClientZ does not exist"); expectThrows(IllegalArgumentException.class, () -> runCommand("ClientZ"));
runCommand("ClientZ"); assertThat(thrown).hasMessageThat().contains("Registrar with id ClientZ does not exist");
} }
@Test @Test
public void testFailure_noRegistrarName() throws Exception { public void testFailure_noRegistrarName() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand());
runCommand();
} }
@Test @Test
public void testFailure_oneRegistrarDoesNotExist() throws Exception { public void testFailure_oneRegistrarDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrar with id ClientZ does not exist"); expectThrows(IllegalArgumentException.class, () -> runCommand("NewRegistrar", "ClientZ"));
runCommand("NewRegistrar", "ClientZ"); assertThat(thrown).hasMessageThat().contains("Registrar with id ClientZ does not exist");
} }
} }

View file

@ -14,6 +14,7 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveContact; import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.testing.DatastoreHelper.persistActiveDomain;
@ -21,6 +22,8 @@ import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistDeletedContact; import static google.registry.testing.DatastoreHelper.persistDeletedContact;
import static google.registry.testing.DatastoreHelper.persistDeletedDomain; import static google.registry.testing.DatastoreHelper.persistDeletedDomain;
import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
@ -68,10 +71,16 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
@Test @Test
public void testFailure_domain_oneDoesNotExist() throws Exception { public void testFailure_domain_oneDoesNotExist() throws Exception {
persistActiveDomain("example.tld"); persistActiveDomain("example.tld");
thrown.expect(NullPointerException.class); NullPointerException thrown =
thrown.expectMessage("Could not load resource for key: Key<?>(DomainBase(\"4-TLD\"))"); expectThrows(
runCommand( NullPointerException.class,
"agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw", "agR0ZXN0chULEgpEb21haW5CYXNlIgU0LVRMRAw"); () ->
runCommand(
"agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw",
"agR0ZXN0chULEgpEb21haW5CYXNlIgU0LVRMRAw"));
assertThat(thrown)
.hasMessageThat()
.contains("Could not load resource for key: Key<?>(DomainBase(\"4-TLD\"))");
} }
@Test @Test
@ -111,11 +120,16 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
@Test @Test
public void testFailure_contact_oneDoesNotExist() throws Exception { public void testFailure_contact_oneDoesNotExist() throws Exception {
persistActiveContact("sh8013"); persistActiveContact("sh8013");
thrown.expect(NullPointerException.class); NullPointerException thrown =
thrown.expectMessage("Could not load resource for key: Key<?>(ContactResource(\"3-ROID\"))"); expectThrows(
runCommand( NullPointerException.class,
"agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw", () ->
"agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjMtUk9JRAw"); runCommand(
"agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw",
"agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjMtUk9JRAw"));
assertThat(thrown)
.hasMessageThat()
.contains("Could not load resource for key: Key<?>(ContactResource(\"3-ROID\"))");
} }
@Test @Test
@ -155,11 +169,16 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
@Test @Test
public void testFailure_host_oneDoesNotExist() throws Exception { public void testFailure_host_oneDoesNotExist() throws Exception {
persistActiveHost("ns1.example.tld"); persistActiveHost("ns1.example.tld");
thrown.expect(NullPointerException.class); NullPointerException thrown =
thrown.expectMessage("Could not load resource for key: Key<?>(HostResource(\"3-ROID\"))"); expectThrows(
runCommand( NullPointerException.class,
"agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw", () ->
"agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjMtUk9JRAw"); runCommand(
"agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw",
"agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjMtUk9JRAw"));
assertThat(thrown)
.hasMessageThat()
.contains("Could not load resource for key: Key<?>(HostResource(\"3-ROID\"))");
} }
@Test @Test
@ -186,21 +205,25 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
@Test @Test
public void testFailure_keyDoesNotExist() throws Exception { public void testFailure_keyDoesNotExist() throws Exception {
thrown.expect(NullPointerException.class); NullPointerException thrown =
thrown.expectMessage("Could not load resource for key: Key<?>(DomainBase(\"2-TLD\"))"); expectThrows(
runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw"); NullPointerException.class,
() -> runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw"));
assertThat(thrown)
.hasMessageThat()
.contains("Could not load resource for key: Key<?>(DomainBase(\"2-TLD\"))");
} }
@Test @Test
public void testFailure_nonsenseKey() throws Exception { public void testFailure_nonsenseKey() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Could not parse Reference"); expectThrows(
runCommand("agR0ZXN0chULEgpEb21haW5CYXN"); IllegalArgumentException.class, () -> runCommand("agR0ZXN0chULEgpEb21haW5CYXN"));
assertThat(thrown).hasMessageThat().contains("Could not parse Reference");
} }
@Test @Test
public void testFailure_noParameters() throws Exception { public void testFailure_noParameters() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand());
runCommand();
} }
} }

View file

@ -16,6 +16,7 @@ package google.registry.tools;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.createTlds; import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.junit.Test; import org.junit.Test;
@ -38,20 +39,17 @@ public class GetTldCommandTest extends CommandTestCase<GetTldCommand> {
@Test @Test
public void testFailure_tldDoesNotExist() throws Exception { public void testFailure_tldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("xn--q9jyb4c"));
runCommand("xn--q9jyb4c");
} }
@Test @Test
public void testFailure_noTldName() throws Exception { public void testFailure_noTldName() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand());
runCommand();
} }
@Test @Test
public void testFailure_oneTldDoesNotExist() throws Exception { public void testFailure_oneTldDoesNotExist() throws Exception {
createTld("xn--q9jyb4c"); createTld("xn--q9jyb4c");
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("xn--q9jyb4c", "example"));
runCommand("xn--q9jyb4c", "example");
} }
} }

View file

@ -17,6 +17,7 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.createTlds; import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import google.registry.model.common.Cursor; import google.registry.model.common.Cursor;
@ -49,9 +50,9 @@ public class ListCursorsCommandTest extends CommandTestCase<ListCursorsCommand>
@Test @Test
public void testListCursors_badCursor_throwsIae() throws Exception { public void testListCursors_badCursor_throwsIae() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("Invalid value for --type parameter."); expectThrows(ParameterException.class, () -> runCommand("--type=love"));
runCommand("--type=love"); assertThat(thrown).hasMessageThat().contains("Invalid value for --type parameter.");
} }
@Test @Test

View file

@ -14,6 +14,9 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import google.registry.tools.server.ListDomainsAction; import google.registry.tools.server.ListDomainsAction;
@ -43,8 +46,10 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase<ListDomai
@Test @Test
public void test_tldsParamTooLong() throws Exception { public void test_tldsParamTooLong() throws Exception {
String tldsParam = "--tld=foo,bar" + Strings.repeat(",baz", 300); String tldsParam = "--tld=foo,bar" + Strings.repeat(",baz", 300);
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Total length of TLDs is too long for URL parameter"); expectThrows(IllegalArgumentException.class, () -> runCommand(tldsParam));
runCommand(tldsParam); assertThat(thrown)
.hasMessageThat()
.contains("Total length of TLDs is too long for URL parameter");
} }
} }

View file

@ -92,13 +92,6 @@ public class LoadTestCommandTest extends CommandTestCase<LoadTestCommand> {
eq(MediaType.PLAIN_TEXT_UTF_8), eq(MediaType.PLAIN_TEXT_UTF_8),
eq(new byte[0])); eq(new byte[0]));
} }
@Test
public void test_prompt() throws Exception {
thrown.expect(IllegalStateException.class);
runCommand();
verifyZeroInteractions(connection);
assertInStderr("Unable to access stdin (are you running with bazel run?)");
}
@Test @Test
public void test_badTLD() throws Exception { public void test_badTLD() throws Exception {

View file

@ -22,6 +22,8 @@ import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar; import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
@ -32,7 +34,6 @@ import org.joda.time.DateTime;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -44,10 +45,6 @@ public class MutatingCommandTest {
public final AppEngineRule appEngine = AppEngineRule.builder() public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore() .withDatastore()
.build(); .build();
@Rule
public final ExpectedException thrown = ExpectedException.none();
Registrar registrar1; Registrar registrar1;
Registrar registrar2; Registrar registrar2;
Registrar newRegistrar1; Registrar newRegistrar1;
@ -298,8 +295,7 @@ public class MutatingCommandTest {
stageEntityChange(null, null); stageEntityChange(null, null);
} }
}; };
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> command.init());
command.init();
} }
@Test @Test
@ -313,9 +309,11 @@ public class MutatingCommandTest {
.build()); .build());
} }
}; };
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Cannot apply multiple changes for the same entity"); expectThrows(IllegalArgumentException.class, () -> command.init());
command.init(); assertThat(thrown)
.hasMessageThat()
.contains("Cannot apply multiple changes for the same entity");
} }
@Test @Test
@ -326,9 +324,11 @@ public class MutatingCommandTest {
stageEntityChange(host1, host2); stageEntityChange(host1, host2);
} }
}; };
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Both entity versions in an update must have the same Key."); expectThrows(IllegalArgumentException.class, () -> command.init());
command.init(); assertThat(thrown)
.hasMessageThat()
.contains("Both entity versions in an update must have the same Key.");
} }
@Test @Test
@ -339,9 +339,11 @@ public class MutatingCommandTest {
stageEntityChange(registrar1, registrar2); stageEntityChange(registrar1, registrar2);
} }
}; };
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Both entity versions in an update must have the same Key."); expectThrows(IllegalArgumentException.class, () -> command.init());
command.init(); assertThat(thrown)
.hasMessageThat()
.contains("Both entity versions in an update must have the same Key.");
} }
@Test @Test
@ -352,9 +354,11 @@ public class MutatingCommandTest {
stageEntityChange(host1, registrar1); stageEntityChange(host1, registrar1);
} }
}; };
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Both entity versions in an update must have the same Key."); expectThrows(IllegalArgumentException.class, () -> command.init());
command.init(); assertThat(thrown)
.hasMessageThat()
.contains("Both entity versions in an update must have the same Key.");
} }
@Test @Test
@ -367,9 +371,9 @@ public class MutatingCommandTest {
}; };
command.init(); command.init();
persistResource(newHost1); persistResource(newHost1);
thrown.expect(IllegalStateException.class); IllegalStateException thrown =
thrown.expectMessage("Entity changed since init() was called."); expectThrows(IllegalStateException.class, () -> command.execute());
command.execute(); assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
} }
@Test @Test
@ -382,9 +386,9 @@ public class MutatingCommandTest {
}; };
command.init(); command.init();
persistResource(newHost1); persistResource(newHost1);
thrown.expect(IllegalStateException.class); IllegalStateException thrown =
thrown.expectMessage("Entity changed since init() was called."); expectThrows(IllegalStateException.class, () -> command.execute());
command.execute(); assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
} }
@Test @Test
@ -397,9 +401,9 @@ public class MutatingCommandTest {
}; };
command.init(); command.init();
persistResource(newHost1); persistResource(newHost1);
thrown.expect(IllegalStateException.class); IllegalStateException thrown =
thrown.expectMessage("Entity changed since init() was called."); expectThrows(IllegalStateException.class, () -> command.execute());
command.execute(); assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
} }
@Test @Test
@ -412,8 +416,8 @@ public class MutatingCommandTest {
}; };
command.init(); command.init();
deleteResource(host1); deleteResource(host1);
thrown.expect(IllegalStateException.class); IllegalStateException thrown =
thrown.expectMessage("Entity changed since init() was called."); expectThrows(IllegalStateException.class, () -> command.execute());
command.execute(); assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
} }
} }

View file

@ -15,10 +15,9 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.assertThrows;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.JUnit4; import org.junit.runners.JUnit4;
@ -26,13 +25,9 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class) @RunWith(JUnit4.class)
public class RegistryToolEnvironmentTest { public class RegistryToolEnvironmentTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testGet_withoutSetup_throws() throws Exception { public void testGet_withoutSetup_throws() throws Exception {
thrown.expect(IllegalStateException.class); assertThrows(IllegalStateException.class, () -> RegistryToolEnvironment.get());
RegistryToolEnvironment.get();
} }
@Test @Test
@ -72,16 +67,18 @@ public class RegistryToolEnvironmentTest {
@Test @Test
public void testFromArgs_envFlagAfterCommandName_getsIgnored() throws Exception { public void testFromArgs_envFlagAfterCommandName_getsIgnored() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
RegistryToolEnvironment.parseFromArgs(new String[] { IllegalArgumentException.class,
"registrar_activity_report", () ->
"-e", "1406851199"}); RegistryToolEnvironment.parseFromArgs(
new String[] {"registrar_activity_report", "-e", "1406851199"}));
} }
@Test @Test
public void testFromArgs_missingEnvironmentFlag_throwsIae() throws Exception { public void testFromArgs_missingEnvironmentFlag_throwsIae() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
RegistryToolEnvironment.parseFromArgs(new String[] {}); IllegalArgumentException.class,
() -> RegistryToolEnvironment.parseFromArgs(new String[] {}));
} }
@Test @Test
@ -106,7 +103,8 @@ public class RegistryToolEnvironmentTest {
@Test @Test
public void testFromArgs_badName_throwsIae() throws Exception { public void testFromArgs_badName_throwsIae() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
RegistryToolEnvironment.parseFromArgs(new String[] { "-e", "alphaville" }); IllegalArgumentException.class,
() -> RegistryToolEnvironment.parseFromArgs(new String[] {"-e", "alphaville"}));
} }
} }

View file

@ -22,6 +22,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistPremiumList; import static google.registry.testing.DatastoreHelper.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
@ -203,132 +204,168 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
@Test @Test
public void testFailure_missingIpWhitelist() throws Exception { public void testFailure_missingIpWhitelist() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("option is required: -w, --ip_whitelist"); expectThrows(
runCommandForced( ParameterException.class,
"--registrar=blobio", () ->
"--dns_writers=VoidDnsWriter", runCommandForced(
"--certfile=" + getCertFilename()); "--registrar=blobio",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("option is required: -w, --ip_whitelist");
} }
@Test @Test
public void testFailure_missingRegistrar() throws Exception { public void testFailure_missingRegistrar() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("option is required: -r, --registrar"); expectThrows(
runCommandForced( ParameterException.class,
"--ip_whitelist=1.1.1.1", () ->
"--dns_writers=VoidDnsWriter", runCommandForced(
"--certfile=" + getCertFilename()); "--ip_whitelist=1.1.1.1",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("option is required: -r, --registrar");
} }
@Test @Test
public void testFailure_missingCertificateFile() throws Exception { public void testFailure_missingCertificateFile() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("option is required: -c, --certfile"); expectThrows(
runCommandForced( ParameterException.class,
"--ip_whitelist=1.1.1.1", () ->
"--dns_writers=VoidDnsWriter", runCommandForced(
"--registrar=blobio"); "--ip_whitelist=1.1.1.1", "--dns_writers=VoidDnsWriter", "--registrar=blobio"));
assertThat(thrown).hasMessageThat().contains("option is required: -c, --certfile");
} }
@Test @Test
public void testFailure_missingDnsWriter() throws Exception { public void testFailure_missingDnsWriter() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("option is required: --dns_writers"); expectThrows(
runCommandForced( ParameterException.class,
"--ip_whitelist=1.1.1.1", () ->
"--certfile=" + getCertFilename(), runCommandForced(
"--registrar=blobio"); "--ip_whitelist=1.1.1.1",
"--certfile=" + getCertFilename(),
"--registrar=blobio"));
assertThat(thrown).hasMessageThat().contains("option is required: --dns_writers");
} }
@Test @Test
public void testFailure_invalidCert() throws Exception { public void testFailure_invalidCert() throws Exception {
thrown.expect(CertificateParsingException.class); CertificateParsingException thrown =
thrown.expectMessage("No X509Certificate found"); expectThrows(
runCommandForced( CertificateParsingException.class,
"--ip_whitelist=1.1.1.1", () ->
"--registrar=blobio", runCommandForced(
"--dns_writers=VoidDnsWriter", "--ip_whitelist=1.1.1.1",
"--certfile=/dev/null"); "--registrar=blobio",
"--dns_writers=VoidDnsWriter",
"--certfile=/dev/null"));
assertThat(thrown).hasMessageThat().contains("No X509Certificate found");
} }
@Test @Test
public void testFailure_invalidRegistrar() throws Exception { public void testFailure_invalidRegistrar() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrar name is invalid"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--ip_whitelist=1.1.1.1", () ->
"--registrar=3blobio", runCommandForced(
"--dns_writers=VoidDnsWriter", "--ip_whitelist=1.1.1.1",
"--certfile=" + getCertFilename()); "--registrar=3blobio",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("Registrar name is invalid");
} }
@Test @Test
public void testFailure_invalidDnsWriter() throws Exception { public void testFailure_invalidDnsWriter() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Invalid DNS writer name(s) specified: [InvalidDnsWriter]"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--ip_whitelist=1.1.1.1", () ->
"--registrar=blobio", runCommandForced(
"--dns_writers=InvalidDnsWriter", "--ip_whitelist=1.1.1.1",
"--certfile=" + getCertFilename()); "--registrar=blobio",
"--dns_writers=InvalidDnsWriter",
"--certfile=" + getCertFilename()));
assertThat(thrown)
.hasMessageThat()
.contains("Invalid DNS writer name(s) specified: [InvalidDnsWriter]");
} }
@Test @Test
public void testFailure_registrarTooShort() throws Exception { public void testFailure_registrarTooShort() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrar name is invalid"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--ip_whitelist=1.1.1.1", () ->
"--registrar=bl", runCommandForced(
"--dns_writers=VoidDnsWriter", "--ip_whitelist=1.1.1.1",
"--certfile=" + getCertFilename()); "--registrar=bl",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("Registrar name is invalid");
} }
@Test @Test
public void testFailure_registrarTooLong() throws Exception { public void testFailure_registrarTooLong() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrar name is invalid"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--ip_whitelist=1.1.1.1", () ->
"--registrar=blobiotoooolong", runCommandForced(
"--dns_writers=VoidDnsWriter", "--ip_whitelist=1.1.1.1",
"--certfile=" + getCertFilename()); "--registrar=blobiotoooolong",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("Registrar name is invalid");
} }
@Test @Test
public void testFailure_registrarInvalidCharacter() throws Exception { public void testFailure_registrarInvalidCharacter() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrar name is invalid"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--ip_whitelist=1.1.1.1", () ->
"--registrar=blo#bio", runCommandForced(
"--dns_writers=VoidDnsWriter", "--ip_whitelist=1.1.1.1",
"--certfile=" + getCertFilename()); "--registrar=blo#bio",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("Registrar name is invalid");
} }
@Test @Test
public void testFailure_invalidPremiumList() throws Exception { public void testFailure_invalidPremiumList() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("The premium list 'foo' doesn't exist"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--ip_whitelist=1.1.1.1", () ->
"--registrar=blobio", runCommandForced(
"--dns_writers=VoidDnsWriter", "--ip_whitelist=1.1.1.1",
"--certfile=" + getCertFilename(), "--registrar=blobio",
"--premium_list=foo"); "--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename(),
"--premium_list=foo"));
assertThat(thrown).hasMessageThat().contains("The premium list 'foo' doesn't exist");
} }
@Test @Test
public void testFailure_tldExists() throws Exception { public void testFailure_tldExists() throws Exception {
createTld("blobio-sunrise"); createTld("blobio-sunrise");
thrown.expect(IllegalStateException.class); IllegalStateException thrown =
thrown.expectMessage("TLD 'blobio-sunrise' already exists"); expectThrows(
runCommandForced( IllegalStateException.class,
"--ip_whitelist=1.1.1.1", () ->
"--registrar=blobio", runCommandForced(
"--dns_writers=VoidDnsWriter", "--ip_whitelist=1.1.1.1",
"--certfile=" + getCertFilename()); "--registrar=blobio",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("TLD 'blobio-sunrise' already exists");
} }
@Test @Test
@ -338,12 +375,15 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
.setRegistrarName("blobio-1") .setRegistrarName("blobio-1")
.build(); .build();
persistResource(registrar); persistResource(registrar);
thrown.expect(IllegalStateException.class); IllegalStateException thrown =
thrown.expectMessage("Registrar blobio-1 already exists"); expectThrows(
runCommandForced( IllegalStateException.class,
"--ip_whitelist=1.1.1.1", () ->
"--registrar=blobio", runCommandForced(
"--dns_writers=VoidDnsWriter", "--ip_whitelist=1.1.1.1",
"--certfile=" + getCertFilename()); "--registrar=blobio",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("Registrar blobio-1 already exists");
} }
} }

View file

@ -14,11 +14,13 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveDomain; import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -150,46 +152,58 @@ public class UniformRapidSuspensionCommandTest
@Test @Test
public void testFailure_locksToPreserveWithoutUndo() throws Exception { public void testFailure_locksToPreserveWithoutUndo() throws Exception {
persistActiveDomain("evil.tld"); persistActiveDomain("evil.tld");
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("--undo"); expectThrows(
runCommandForced("--domain_name=evil.tld", "--locks_to_preserve=serverDeleteProhibited"); IllegalArgumentException.class,
() ->
runCommandForced(
"--domain_name=evil.tld", "--locks_to_preserve=serverDeleteProhibited"));
assertThat(thrown).hasMessageThat().contains("--undo");
} }
@Test @Test
public void testFailure_domainNameRequired() throws Exception { public void testFailure_domainNameRequired() throws Exception {
persistActiveDomain("evil.tld"); persistActiveDomain("evil.tld");
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--domain_name"); expectThrows(
runCommandForced("--hosts=urs1.example.com,urs2.example.com"); ParameterException.class,
() -> runCommandForced("--hosts=urs1.example.com,urs2.example.com"));
assertThat(thrown).hasMessageThat().contains("--domain_name");
} }
@Test @Test
public void testFailure_extraFieldInDsData() throws Exception { public void testFailure_extraFieldInDsData() throws Exception {
persistActiveDomain("evil.tld"); persistActiveDomain("evil.tld");
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Incorrect fields on --dsdata JSON"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--domain_name=evil.tld", () ->
"--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1,\"digest\":\"abc\",\"foo\":1}"); runCommandForced(
"--domain_name=evil.tld",
"--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1,\"digest\":\"abc\",\"foo\":1}"));
assertThat(thrown).hasMessageThat().contains("Incorrect fields on --dsdata JSON");
} }
@Test @Test
public void testFailure_missingFieldInDsData() throws Exception { public void testFailure_missingFieldInDsData() throws Exception {
persistActiveDomain("evil.tld"); persistActiveDomain("evil.tld");
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Incorrect fields on --dsdata JSON"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--domain_name=evil.tld", () ->
"--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1}"); runCommandForced(
"--domain_name=evil.tld",
"--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1}"));
assertThat(thrown).hasMessageThat().contains("Incorrect fields on --dsdata JSON");
} }
@Test @Test
public void testFailure_malformedDsData() throws Exception { public void testFailure_malformedDsData() throws Exception {
persistActiveDomain("evil.tld"); persistActiveDomain("evil.tld");
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Invalid --dsdata JSON"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--domain_name=evil.tld", () -> runCommandForced("--domain_name=evil.tld", "--dsdata=[1,2,3]"));
"--dsdata=[1,2,3]"); assertThat(thrown).hasMessageThat().contains("Invalid --dsdata JSON");
} }
} }

View file

@ -27,6 +27,7 @@ import static google.registry.testing.DatastoreHelper.newDomainApplication;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
@ -270,16 +271,25 @@ public class UpdateApplicationStatusCommandTest
@Test @Test
public void testFailure_applicationDoesNotExist() throws Exception { public void testFailure_applicationDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommandForced("--ids=555-Q9JYB4C", "--msg=\"Application rejected\"", "--status=REJECTED"); IllegalArgumentException.class,
() ->
runCommandForced(
"--ids=555-Q9JYB4C", "--msg=\"Application rejected\"", "--status=REJECTED"));
} }
@Test @Test
public void testFailure_historyClientIdDoesNotExist() throws Exception { public void testFailure_historyClientIdDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("fakeclient"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--history_client_id=fakeclient", "--ids=2-Q9JYB4C", "--msg=Ignored", "--status=REJECTED"); () ->
runCommandForced(
"--history_client_id=fakeclient",
"--ids=2-Q9JYB4C",
"--msg=Ignored",
"--status=REJECTED"));
assertThat(thrown).hasMessageThat().contains("fakeclient");
} }
} }

View file

@ -20,6 +20,7 @@ import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainApplication; import static google.registry.testing.DatastoreHelper.newDomainApplication;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications; import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -131,12 +132,14 @@ public class UpdateClaimsNoticeCommandTest extends CommandTestCase<UpdateClaimsN
@Test @Test
public void testFailure_badClaimsNotice() throws Exception { public void testFailure_badClaimsNotice() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand( IllegalArgumentException.class,
"--id=1-Q9JYB4C", () ->
"--tcn_id=foobarbaz", runCommand(
"--expiration_time=2010-08-16T09:00:00.0Z", "--id=1-Q9JYB4C",
"--accepted_time=2009-08-16T09:00:00.0Z"); "--tcn_id=foobarbaz",
"--expiration_time=2010-08-16T09:00:00.0Z",
"--accepted_time=2009-08-16T09:00:00.0Z"));
} }
@Test @Test
@ -160,12 +163,13 @@ public class UpdateClaimsNoticeCommandTest extends CommandTestCase<UpdateClaimsN
domainApplication = persistResource(domainApplication.asBuilder() domainApplication = persistResource(domainApplication.asBuilder()
.setEncodedSignedMarks(ImmutableList.of(EncodedSignedMark.create("base64", "AAAAA"))) .setEncodedSignedMarks(ImmutableList.of(EncodedSignedMark.create("base64", "AAAAA")))
.build()); .build());
thrown.expect(IllegalArgumentException.class); assertThrows(
IllegalArgumentException.class,
runCommand( () ->
"--id=1-Q9JYB4C", runCommand(
"--tcn_id=370d0b7c9223372036854775807", "--id=1-Q9JYB4C",
"--expiration_time=2010-08-16T09:00:00.0Z", "--tcn_id=370d0b7c9223372036854775807",
"--accepted_time=2009-08-16T09:00:00.0Z"); "--expiration_time=2010-08-16T09:00:00.0Z",
"--accepted_time=2009-08-16T09:00:00.0Z"));
} }
} }

View file

@ -18,6 +18,8 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import google.registry.model.common.Cursor; import google.registry.model.common.Cursor;
@ -110,14 +112,17 @@ public class UpdateCursorsCommandTest extends CommandTestCase<UpdateCursorsComma
@Test @Test
public void testFailure_badTld() throws Exception { public void testFailure_badTld() throws Exception {
thrown.expect(RegistryNotFoundException.class); assertThrows(
runCommandForced("--type=brda", "--timestamp=1984-12-18T00:00:00Z", "bar"); RegistryNotFoundException.class,
() -> runCommandForced("--type=brda", "--timestamp=1984-12-18T00:00:00Z", "bar"));
} }
@Test @Test
public void testFailure_badCursorType() throws Exception { public void testFailure_badCursorType() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("Invalid value for --type parameter"); expectThrows(
runCommandForced("--type=rbda", "--timestamp=1984-12-18T00:00:00Z", "foo"); ParameterException.class,
() -> runCommandForced("--type=rbda", "--timestamp=1984-12-18T00:00:00Z", "foo"));
assertThat(thrown).hasMessageThat().contains("Invalid value for --type parameter");
} }
} }

View file

@ -192,130 +192,197 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
@Test @Test
public void testFailure_duplicateDomains() throws Exception { public void testFailure_duplicateDomains() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Duplicate arguments found"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--client=NewRegistrar", () ->
"--registrant=crr-admin", runCommandForced(
"--password=2fooBAR", "--client=NewRegistrar",
"example.tld", "--registrant=crr-admin",
"example.tld"); "--password=2fooBAR",
"example.tld",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("Duplicate arguments found");
} }
@Test @Test
public void testFailure_missingDomain() throws Exception { public void testFailure_missingDomain() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("Main parameters are required"); expectThrows(
runCommandForced("--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR"); ParameterException.class,
() ->
runCommandForced(
"--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR"));
assertThat(thrown).hasMessageThat().contains("Main parameters are required");
} }
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--client"); expectThrows(
runCommandForced("--registrant=crr-admin", "--password=2fooBAR", "example.tld"); ParameterException.class,
() -> runCommandForced("--registrant=crr-admin", "--password=2fooBAR", "example.tld"));
assertThat(thrown).hasMessageThat().contains("--client");
} }
@Test @Test
public void testFailure_addTooManyNameServers() throws Exception { public void testFailure_addTooManyNameServers() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("You can add at most 13 nameservers"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--client=NewRegistrar", () ->
"--add_nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google," runCommandForced(
+ "ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google," "--client=NewRegistrar",
+ "ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google," "--add_nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google,"
+ "ns13.zdns.google,ns14.zdns.google", + "ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google,"
"--add_admins=crr-admin2", + "ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google,"
"--add_techs=crr-tech2", + "ns13.zdns.google,ns14.zdns.google",
"--add_statuses=serverDeleteProhibited", "--add_admins=crr-admin2",
"example.tld"); "--add_techs=crr-tech2",
"--add_statuses=serverDeleteProhibited",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("You can add at most 13 nameservers");
} }
@Test @Test
public void testFailure_providedNameserversAndAddNameservers() throws Exception { public void testFailure_providedNameserversAndAddNameservers() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("If you provide the nameservers flag, " expectThrows(
+ "you cannot use the add_nameservers and remove_nameservers flags."); IllegalArgumentException.class,
runCommandForced( () ->
"--client=NewRegistrar", runCommandForced(
"--add_nameservers=ns1.zdns.google", "--client=NewRegistrar",
"--nameservers=ns2.zdns.google,ns3.zdns.google", "--add_nameservers=ns1.zdns.google",
"example.tld"); "--nameservers=ns2.zdns.google,ns3.zdns.google",
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.contains(
"If you provide the nameservers flag, "
+ "you cannot use the add_nameservers and remove_nameservers flags.");
} }
@Test @Test
public void testFailure_providedNameserversAndRemoveNameservers() throws Exception { public void testFailure_providedNameserversAndRemoveNameservers() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("If you provide the nameservers flag, " expectThrows(
+ "you cannot use the add_nameservers and remove_nameservers flags."); IllegalArgumentException.class,
runCommandForced( () ->
"--client=NewRegistrar", runCommandForced(
"--remove_nameservers=ns1.zdns.google", "--client=NewRegistrar",
"--nameservers=ns2.zdns.google,ns3.zdns.google", "--remove_nameservers=ns1.zdns.google",
"example.tld"); "--nameservers=ns2.zdns.google,ns3.zdns.google",
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.contains(
"If you provide the nameservers flag, "
+ "you cannot use the add_nameservers and remove_nameservers flags.");
} }
@Test @Test
public void testFailure_providedAdminsAndAddAdmins() throws Exception { public void testFailure_providedAdminsAndAddAdmins() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage( expectThrows(
"If you provide the admins flag, you cannot use the add_admins and remove_admins flags."); IllegalArgumentException.class,
runCommandForced( () ->
"--client=NewRegistrar", "--add_admins=crr-admin2", "--admins=crr-admin2", "example.tld"); runCommandForced(
"--client=NewRegistrar",
"--add_admins=crr-admin2",
"--admins=crr-admin2",
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"If you provide the admins flag, "
+ "you cannot use the add_admins and remove_admins flags.");
} }
@Test @Test
public void testFailure_providedAdminsAndRemoveAdmins() throws Exception { public void testFailure_providedAdminsAndRemoveAdmins() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage( expectThrows(
"If you provide the admins flag, you cannot use the add_admins and remove_admins flags."); IllegalArgumentException.class,
runCommandForced( () ->
"--client=NewRegistrar", runCommandForced(
"--remove_admins=crr-admin2", "--client=NewRegistrar",
"--admins=crr-admin2", "--remove_admins=crr-admin2",
"example.tld"); "--admins=crr-admin2",
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"If you provide the admins flag, "
+ "you cannot use the add_admins and remove_admins flags.");
} }
@Test @Test
public void testFailure_providedTechsAndAddTechs() throws Exception { public void testFailure_providedTechsAndAddTechs() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage( expectThrows(
"If you provide the techs flag, you cannot use the add_techs and remove_techs flags."); IllegalArgumentException.class,
runCommandForced( () ->
"--client=NewRegistrar", "--add_techs=crr-tech2", "--techs=crr-tech2", "example.tld"); runCommandForced(
"--client=NewRegistrar",
"--add_techs=crr-tech2",
"--techs=crr-tech2",
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.contains(
"If you provide the techs flag, you cannot use the add_techs and remove_techs flags.");
} }
@Test @Test
public void testFailure_providedTechsAndRemoveTechs() throws Exception { public void testFailure_providedTechsAndRemoveTechs() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage( expectThrows(
"If you provide the techs flag, you cannot use the add_techs and remove_techs flags."); IllegalArgumentException.class,
runCommandForced( () ->
"--client=NewRegistrar", "--remove_techs=crr-tech2", "--techs=crr-tech2", "example.tld"); runCommandForced(
"--client=NewRegistrar",
"--remove_techs=crr-tech2",
"--techs=crr-tech2",
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.contains(
"If you provide the techs flag, you cannot use the add_techs and remove_techs flags.");
} }
@Test @Test
public void testFailure_providedStatusesAndAddStatuses() throws Exception { public void testFailure_providedStatusesAndAddStatuses() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("If you provide the statuses flag, " expectThrows(
+ "you cannot use the add_statuses and remove_statuses flags."); IllegalArgumentException.class,
runCommandForced( () ->
"--client=NewRegistrar", runCommandForced(
"--add_statuses=serverHold", "--client=NewRegistrar",
"--statuses=crr-serverHold", "--add_statuses=serverHold",
"example.tld"); "--statuses=crr-serverHold",
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.contains(
"If you provide the statuses flag, "
+ "you cannot use the add_statuses and remove_statuses flags.");
} }
@Test @Test
public void testFailure_providedStatusesAndRemoveStatuses() throws Exception { public void testFailure_providedStatusesAndRemoveStatuses() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("If you provide the statuses flag, " expectThrows(
+ "you cannot use the add_statuses and remove_statuses flags."); IllegalArgumentException.class,
runCommandForced( () ->
"--client=NewRegistrar", runCommandForced(
"--remove_statuses=serverHold", "--client=NewRegistrar",
"--statuses=crr-serverHold", "--remove_statuses=serverHold",
"example.tld"); "--statuses=crr-serverHold",
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.contains(
"If you provide the statuses flag, "
+ "you cannot use the add_statuses and remove_statuses flags.");
} }
} }

View file

@ -21,6 +21,8 @@ import static google.registry.testing.CertificateSamples.SAMPLE_CERT_HASH;
import static google.registry.testing.DatastoreHelper.createTlds; import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
@ -70,9 +72,11 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
.setIanaIdentifier(null) .setIanaIdentifier(null)
.setPhonePasscode(null) .setPhonePasscode(null)
.build()); .build());
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("--passcode is required for REAL registrars."); expectThrows(
runCommand("--registrar_type=REAL", "--iana_id=1000", "--force", "NewRegistrar"); IllegalArgumentException.class,
() -> runCommand("--registrar_type=REAL", "--iana_id=1000", "--force", "NewRegistrar"));
assertThat(thrown).hasMessageThat().contains("--passcode is required for REAL registrars.");
} }
@Test @Test
@ -217,14 +221,17 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
public void testFailure_billingAccountMap_doesNotContainEntryForTldAllowed() throws Exception { public void testFailure_billingAccountMap_doesNotContainEntryForTldAllowed() throws Exception {
createTlds("foo"); createTlds("foo");
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty(); assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty();
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("USD"); expectThrows(
runCommand( IllegalArgumentException.class,
"--billing_account_map=JPY=789xyz", () ->
"--allowed_tlds=foo", runCommand(
"--force", "--billing_account_map=JPY=789xyz",
"--registrar_type=REAL", "--allowed_tlds=foo",
"NewRegistrar"); "--force",
"--registrar_type=REAL",
"NewRegistrar"));
assertThat(thrown).hasMessageThat().contains("USD");
} }
@Test @Test
@ -276,11 +283,15 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
.setAmount(Money.parse("USD 10.00")) .setAmount(Money.parse("USD 10.00"))
.build()); .build());
assertThat(registrar.getBillingMethod()).isEqualTo(BillingMethod.EXTERNAL); assertThat(registrar.getBillingMethod()).isEqualTo(BillingMethod.EXTERNAL);
thrown.expect(IllegalStateException.class); IllegalStateException thrown =
thrown.expectMessage( expectThrows(
"Refusing to change billing method on Registrar 'NewRegistrar' from EXTERNAL to BRAINTREE" IllegalStateException.class,
+ " because current balance is non-zero: {USD=USD 10.00}"); () -> runCommand("--billing_method=braintree", "--force", "NewRegistrar"));
runCommand("--billing_method=braintree", "--force", "NewRegistrar"); assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"Refusing to change billing method on Registrar 'NewRegistrar' from EXTERNAL to "
+ "BRAINTREE because current balance is non-zero: {USD=USD 10.00}");
} }
@Test @Test
@ -437,174 +448,267 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test @Test
public void testFailure_invalidRegistrarType() throws Exception { public void testFailure_invalidRegistrarType() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--registrar_type=INVALID_TYPE", "--force", "NewRegistrar"); ParameterException.class,
() -> runCommand("--registrar_type=INVALID_TYPE", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_invalidRegistrarState() throws Exception { public void testFailure_invalidRegistrarState() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--registrar_state=INVALID_STATE", "--force", "NewRegistrar"); ParameterException.class,
() -> runCommand("--registrar_state=INVALID_STATE", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_negativeIanaId() throws Exception { public void testFailure_negativeIanaId() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--iana_id=-1", "--force", "NewRegistrar"); IllegalArgumentException.class,
() -> runCommand("--iana_id=-1", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_nonIntegerIanaId() throws Exception { public void testFailure_nonIntegerIanaId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--iana_id=ABC123", "--force", "NewRegistrar"); ParameterException.class, () -> runCommand("--iana_id=ABC123", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_negativeBillingId() throws Exception { public void testFailure_negativeBillingId() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--billing_id=-1", "--force", "NewRegistrar"); IllegalArgumentException.class,
() -> runCommand("--billing_id=-1", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_nonIntegerBillingId() throws Exception { public void testFailure_nonIntegerBillingId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--billing_id=ABC123", "--force", "NewRegistrar"); ParameterException.class,
() -> runCommand("--billing_id=ABC123", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_passcodeTooShort() throws Exception { public void testFailure_passcodeTooShort() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--passcode=0123", "--force", "NewRegistrar"); IllegalArgumentException.class,
() -> runCommand("--passcode=0123", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_passcodeTooLong() throws Exception { public void testFailure_passcodeTooLong() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--passcode=012345", "--force", "NewRegistrar"); IllegalArgumentException.class,
() -> runCommand("--passcode=012345", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_invalidPasscode() throws Exception { public void testFailure_invalidPasscode() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--passcode=code1", "--force", "NewRegistrar"); IllegalArgumentException.class,
() -> runCommand("--passcode=code1", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_allowedTldDoesNotExist() throws Exception { public void testFailure_allowedTldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--allowed_tlds=foobar", "--force", "NewRegistrar"); IllegalArgumentException.class,
() -> runCommand("--allowed_tlds=foobar", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_addAllowedTldDoesNotExist() throws Exception { public void testFailure_addAllowedTldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--add_allowed_tlds=foobar", "--force", "NewRegistrar"); IllegalArgumentException.class,
() -> runCommand("--add_allowed_tlds=foobar", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_allowedTldsAndAddAllowedTlds() throws Exception { public void testFailure_allowedTldsAndAddAllowedTlds() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--allowed_tlds=bar", "--add_allowed_tlds=foo", "--force", "NewRegistrar"); IllegalArgumentException.class,
() ->
runCommand("--allowed_tlds=bar", "--add_allowed_tlds=foo", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_invalidIpWhitelist() throws Exception { public void testFailure_invalidIpWhitelist() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--ip_whitelist=foobarbaz", "--force", "NewRegistrar"); IllegalArgumentException.class,
() -> runCommand("--ip_whitelist=foobarbaz", "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_invalidCertFileContents() throws Exception { public void testFailure_invalidCertFileContents() throws Exception {
thrown.expect(Exception.class); assertThrows(
runCommand("--cert_file=" + writeToTmpFile("ABCDEF"), "--force", "NewRegistrar"); Exception.class,
() -> runCommand("--cert_file=" + writeToTmpFile("ABCDEF"), "--force", "NewRegistrar"));
} }
@Test @Test
public void testFailure_certHashAndCertFile() throws Exception { public void testFailure_certHashAndCertFile() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--cert_file=" + getCertFilename(), "--cert_hash=ABCDEF", "--force", "NewRegistrar"); IllegalArgumentException.class,
() ->
runCommand(
"--cert_file=" + getCertFilename(),
"--cert_hash=ABCDEF",
"--force",
"NewRegistrar"));
} }
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(ParameterException.class, () -> runCommand("--force"));
runCommand("--force");
} }
@Test @Test
public void testFailure_missingStreetLines() throws Exception { public void testFailure_missingStreetLines() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--city Brooklyn", "--state NY", "--zip 11223", "--cc US", "--force", IllegalArgumentException.class,
"NewRegistrar"); () ->
runCommand(
"--city Brooklyn",
"--state NY",
"--zip 11223",
"--cc US",
"--force",
"NewRegistrar"));
} }
@Test @Test
public void testFailure_missingCity() throws Exception { public void testFailure_missingCity() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"", IllegalArgumentException.class,
"--state NY", "--zip 11223", "--cc US", "--force", "NewRegistrar"); () ->
runCommand(
"--street=\"1234 Main St\"",
"--street \"4th Floor\"",
"--street \"Suite 1\"",
"--state NY",
"--zip 11223",
"--cc US",
"--force",
"NewRegistrar"));
} }
@Test @Test
public void testFailure_missingState() throws Exception { public void testFailure_missingState() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"", IllegalArgumentException.class,
"--city Brooklyn", "--zip 11223", "--cc US", "--force", "NewRegistrar"); () ->
runCommand(
"--street=\"1234 Main St\"",
"--street \"4th Floor\"",
"--street \"Suite 1\"",
"--city Brooklyn",
"--zip 11223",
"--cc US",
"--force",
"NewRegistrar"));
} }
@Test @Test
public void testFailure_missingZip() throws Exception { public void testFailure_missingZip() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"", IllegalArgumentException.class,
"--city Brooklyn", "--state NY", "--cc US", "--force", "NewRegistrar"); () ->
runCommand(
"--street=\"1234 Main St\"",
"--street \"4th Floor\"",
"--street \"Suite 1\"",
"--city Brooklyn",
"--state NY",
"--cc US",
"--force",
"NewRegistrar"));
} }
@Test @Test
public void testFailure_missingCc() throws Exception { public void testFailure_missingCc() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"", IllegalArgumentException.class,
"--city Brooklyn", "--state NY", "--zip 11223", "--force", "NewRegistrar"); () ->
runCommand(
"--street=\"1234 Main St\"",
"--street \"4th Floor\"",
"--street \"Suite 1\"",
"--city Brooklyn",
"--state NY",
"--zip 11223",
"--force",
"NewRegistrar"));
} }
@Test @Test
public void testFailure_missingInvalidCc() throws Exception { public void testFailure_missingInvalidCc() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"", IllegalArgumentException.class,
"--city Brooklyn", "--state NY", "--zip 11223", "--cc USA", "--force", "NewRegistrar"); () ->
runCommand(
"--street=\"1234 Main St\"",
"--street \"4th Floor\"",
"--street \"Suite 1\"",
"--city Brooklyn",
"--state NY",
"--zip 11223",
"--cc USA",
"--force",
"NewRegistrar"));
} }
@Test @Test
public void testFailure_tooManyStreetLines() throws Exception { public void testFailure_tooManyStreetLines() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--street \"Attn:Hey You Guys\"", "--street \"1234 Main St\"", IllegalArgumentException.class,
"--street \"4th Floor\"", "--street \"Suite 1\"", "--city Brooklyn", "--state NY", () ->
"--zip 11223", "--cc USA", "--force", "NewRegistrar"); runCommand(
"--street \"Attn:Hey You Guys\"",
"--street \"1234 Main St\"",
"--street \"4th Floor\"",
"--street \"Suite 1\"",
"--city Brooklyn",
"--state NY",
"--zip 11223",
"--cc USA",
"--force",
"NewRegistrar"));
} }
@Test @Test
public void testFailure_tooFewStreetLines() throws Exception { public void testFailure_tooFewStreetLines() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand("--street", "--city Brooklyn", "--state NY", "--zip 11223", "--cc USA", "--force", IllegalArgumentException.class,
"NewRegistrar"); () ->
runCommand(
"--street",
"--city Brooklyn",
"--state NY",
"--zip 11223",
"--cc USA",
"--force",
"NewRegistrar"));
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand("--force", "--unrecognized_flag=foo", "NewRegistrar"); ParameterException.class,
() -> runCommand("--force", "--unrecognized_flag=foo", "NewRegistrar"));
} }
@Test @Test
public void testFailure_doesNotExist() throws Exception { public void testFailure_doesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrar ClientZ not found"); expectThrows(IllegalArgumentException.class, () -> runCommand("--force", "ClientZ"));
runCommand("--force", "ClientZ"); assertThat(thrown).hasMessageThat().contains("Registrar ClientZ not found");
} }
@Test @Test
public void testFailure_registrarNameSimilarToExisting() throws Exception { public void testFailure_registrarNameSimilarToExisting() throws Exception {
thrown.expect(IllegalArgumentException.class); // Note that "tHeRe GiStRaR" normalizes identically to "The Registrar", which is created by
// Normalizes identically to "The Registrar" which is created by AppEngineRule. // AppEngineRule.
runCommand("--name tHeRe GiStRaR", "--force", "NewRegistrar"); assertThrows(
IllegalArgumentException.class,
() -> runCommand("--name tHeRe GiStRaR", "--force", "NewRegistrar"));
} }
} }

View file

@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat; import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED; import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -92,8 +93,11 @@ public class UpdateReservedListCommandTest extends
public void testFailure_reservedListDoesntExist() throws Exception { public void testFailure_reservedListDoesntExist() throws Exception {
String errorMessage = String errorMessage =
"Could not update reserved list xn--q9jyb4c_poobah because it doesn't exist."; "Could not update reserved list xn--q9jyb4c_poobah because it doesn't exist.";
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage(errorMessage); expectThrows(
runCommand("--force", "--name=xn--q9jyb4c_poobah", "--input=" + reservedTermsPath); IllegalArgumentException.class,
() ->
runCommand("--force", "--name=xn--q9jyb4c_poobah", "--input=" + reservedTermsPath));
assertThat(thrown).hasMessageThat().contains(errorMessage);
} }
} }

View file

@ -14,6 +14,8 @@
package google.registry.tools; package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import org.junit.Test; import org.junit.Test;
@ -57,69 +59,123 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateS
@Test @Test
public void testFailure_applyAllRemoveOne_failsDueToOverlap() throws Exception { public void testFailure_applyAllRemoveOne_failsDueToOverlap() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", IllegalArgumentException.class,
"--domain_name=example.tld", "--apply=all", "--remove=serverRenewProhibited"); () ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=true",
"--reason=Test",
"--domain_name=example.tld",
"--apply=all",
"--remove=serverRenewProhibited"));
} }
@Test @Test
public void testFailure_illegalStatus() throws Exception { public void testFailure_illegalStatus() throws Exception {
// The EPP status is a valid one by RFC, but invalid for this command. // The EPP status is a valid one by RFC, but invalid for this command.
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", IllegalArgumentException.class,
"--domain_name=example.tld", "--apply=clientRenewProhibited"); () ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=true",
"--reason=Test",
"--domain_name=example.tld",
"--apply=clientRenewProhibited"));
} }
@Test @Test
public void testFailure_unrecognizedStatus() throws Exception { public void testFailure_unrecognizedStatus() throws Exception {
// Handles a status passed to the command that doesn't correspond to any // Handles a status passed to the command that doesn't correspond to any
// EPP-valid status. // EPP-valid status.
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", IllegalArgumentException.class,
"--domain_name=example.tld", "--apply=foo"); () ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=true",
"--reason=Test",
"--domain_name=example.tld",
"--apply=foo"));
} }
@Test @Test
public void testFailure_mainParameter() throws Exception { public void testFailure_mainParameter() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", ParameterException.class,
"--domain_name=example.tld", "example2.tld", "--apply=serverRenewProhibited"); () ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=true",
"--reason=Test",
"--domain_name=example.tld",
"example2.tld",
"--apply=serverRenewProhibited"));
} }
@Test @Test
public void testFailure_noOp() throws Exception { public void testFailure_noOp() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", "--apply=all", IllegalArgumentException.class,
"--remove=serverRenewProhibited,serverTransferProhibited," () ->
+ "serverDeleteProhibited,serverUpdateProhibited,serverHold", runCommandForced(
"--registrar_request=true", "--reason=Test"); "--client=NewRegistrar",
"--domain_name=example.tld",
"--apply=all",
"--remove=serverRenewProhibited,serverTransferProhibited,"
+ "serverDeleteProhibited,serverUpdateProhibited,serverHold",
"--registrar_request=true",
"--reason=Test"));
} }
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--domain_name=example.tld", "--registrar_request=true", ParameterException.class,
"--apply=serverRenewProhibited", "--reason=Test"); () ->
runCommandForced(
"--domain_name=example.tld",
"--registrar_request=true",
"--apply=serverRenewProhibited",
"--reason=Test"));
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test", ParameterException.class,
"--domain_name=example.tld", "--apply=serverRenewProhibited", "--foo=bar"); () ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=true",
"--reason=Test",
"--domain_name=example.tld",
"--apply=serverRenewProhibited",
"--foo=bar"));
} }
@Test @Test
public void testFailure_noReasonWhenNotRegistrarRequested() throws Exception { public void testFailure_noReasonWhenNotRegistrarRequested() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--registrar_request=false", IllegalArgumentException.class,
"--domain_name=example.tld", "--apply=serverRenewProhibited"); () ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=false",
"--domain_name=example.tld",
"--apply=serverRenewProhibited"));
} }
@Test @Test
public void testFailure_missingRegistrarRequest() throws Exception { public void testFailure_missingRegistrarRequest() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommandForced("--client=NewRegistrar", "--reason=Test", ParameterException.class,
"--domain_name=example.tld", "--apply=serverRenewProhibited"); () ->
runCommandForced(
"--client=NewRegistrar",
"--reason=Test",
"--domain_name=example.tld",
"--apply=serverRenewProhibited"));
} }
} }

View file

@ -465,88 +465,128 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
@Test @Test
public void testFailure_invalidAddGracePeriod() throws Exception { public void testFailure_invalidAddGracePeriod() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Invalid format: \"5m\""); expectThrows(
runCommandForced("--add_grace_period=5m", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--add_grace_period=5m", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\"");
} }
@Test @Test
public void testFailure_invalidRedemptionGracePeriod() throws Exception { public void testFailure_invalidRedemptionGracePeriod() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Invalid format: \"5m\""); expectThrows(
runCommandForced("--redemption_grace_period=5m", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--redemption_grace_period=5m", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\"");
} }
@Test @Test
public void testFailure_invalidPendingDeleteLength() throws Exception { public void testFailure_invalidPendingDeleteLength() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Invalid format: \"5m\""); expectThrows(
runCommandForced("--pending_delete_length=5m", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--pending_delete_length=5m", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Invalid format: \"5m\"");
} }
@Test @Test
public void testFailure_invalidTldState() throws Exception { public void testFailure_invalidTldState() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage( expectThrows(
"INVALID_STATE not formatted correctly or has transition times out of order"); ParameterException.class,
runCommandForced("--tld_state_transitions=" + START_OF_TIME + "=INVALID_STATE", "xn--q9jyb4c"); () ->
runCommandForced(
"--tld_state_transitions=" + START_OF_TIME + "=INVALID_STATE", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("INVALID_STATE not formatted correctly or has transition times out of order");
} }
@Test @Test
public void testFailure_invalidTldStateTransitionTime() throws Exception { public void testFailure_invalidTldStateTransitionTime() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage( expectThrows(
"INVALID_STATE not formatted correctly or has transition times out of order"); ParameterException.class,
runCommandForced("--tld_state_transitions=tomorrow=INVALID_STATE", "xn--q9jyb4c"); () ->
runCommandForced("--tld_state_transitions=tomorrow=INVALID_STATE", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("INVALID_STATE not formatted correctly or has transition times out of order");
} }
@Test @Test
public void testFailure_tldStatesOutOfOrder() throws Exception { public void testFailure_tldStatesOutOfOrder() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("The TLD states are chronologically out of order"); expectThrows(
runCommandForced( IllegalArgumentException.class,
String.format( () ->
"--tld_state_transitions=%s=SUNRISE,%s=PREDELEGATION", now, now.plusMonths(1)), runCommandForced(
"xn--q9jyb4c"); String.format(
"--tld_state_transitions=%s=SUNRISE,%s=PREDELEGATION",
now, now.plusMonths(1)),
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("The TLD states are chronologically out of order");
} }
@Test @Test
public void testFailure_duplicateTldStateTransitions() throws Exception { public void testFailure_duplicateTldStateTransitions() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("The TLD states are chronologically out of order"); expectThrows(
runCommandForced( IllegalArgumentException.class,
String.format("--tld_state_transitions=%s=SUNRISE,%s=SUNRISE", now, now.plusMonths(1)), () ->
"xn--q9jyb4c"); runCommandForced(
String.format(
"--tld_state_transitions=%s=SUNRISE,%s=SUNRISE", now, now.plusMonths(1)),
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("The TLD states are chronologically out of order");
} }
@Test @Test
public void testFailure_duplicateTldStateTransitionTimes() throws Exception { public void testFailure_duplicateTldStateTransitionTimes() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("not formatted correctly or has transition times out of order"); expectThrows(
runCommandForced( ParameterException.class,
String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now), () ->
"xn--q9jyb4c"); runCommandForced(
String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now),
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
} }
@Test @Test
public void testFailure_outOfOrderTldStateTransitionTimes() throws Exception { public void testFailure_outOfOrderTldStateTransitionTimes() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("not formatted correctly or has transition times out of order"); expectThrows(
runCommandForced( ParameterException.class,
String.format( () ->
"--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", runCommandForced(
now, now.minus(Duration.millis(1))), String.format(
"xn--q9jyb4c"); "--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE",
now, now.minus(Duration.millis(1))),
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
} }
@Test @Test
public void testFailure_bothTldStateFlags() throws Exception { public void testFailure_bothTldStateFlags() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Don't pass both --set_current_tld_state and --tld_state_transitions"); expectThrows(
runCommandForced( IllegalArgumentException.class,
String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now.plusDays(1)), () ->
"--set_current_tld_state=GENERAL_AVAILABILITY", runCommandForced(
"xn--q9jyb4c"); String.format(
"--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE",
now, now.plusDays(1)),
"--set_current_tld_state=GENERAL_AVAILABILITY",
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("Don't pass both --set_current_tld_state and --tld_state_transitions");
} }
@Test @Test
@ -558,9 +598,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
START_OF_TIME, TldState.PREDELEGATION, START_OF_TIME, TldState.PREDELEGATION,
now.minusMonths(1), TldState.GENERAL_AVAILABILITY)) now.minusMonths(1), TldState.GENERAL_AVAILABILITY))
.build()); .build());
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("The TLD states are chronologically out of order"); expectThrows(
runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("The TLD states are chronologically out of order");
} }
@Test @Test
@ -572,9 +614,13 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
START_OF_TIME, TldState.PREDELEGATION, START_OF_TIME, TldState.PREDELEGATION,
now.plusMonths(1), TldState.GENERAL_AVAILABILITY)) now.plusMonths(1), TldState.GENERAL_AVAILABILITY))
.build()); .build());
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage(" when there is a later transition already scheduled"); expectThrows(
runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains(" when there is a later transition already scheduled");
} }
@Test @Test
@ -586,99 +632,139 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
START_OF_TIME, TldState.PREDELEGATION, START_OF_TIME, TldState.PREDELEGATION,
now.minusMonths(1), TldState.GENERAL_AVAILABILITY)) now.minusMonths(1), TldState.GENERAL_AVAILABILITY))
.build()); .build());
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("--set_current_tld_state is not safe to use in production."); expectThrows(
runCommandInEnvironment( IllegalArgumentException.class,
RegistryToolEnvironment.PRODUCTION, () ->
"--set_current_tld_state=SUNRISE", runCommandInEnvironment(
"xn--q9jyb4c", RegistryToolEnvironment.PRODUCTION,
"--force"); "--set_current_tld_state=SUNRISE",
"xn--q9jyb4c",
"--force"));
assertThat(thrown)
.hasMessageThat()
.contains("--set_current_tld_state is not safe to use in production.");
} }
@Test @Test
public void testFailure_invalidRenewBillingCost() throws Exception { public void testFailure_invalidRenewBillingCost() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("not formatted correctly or has transition times out of order"); expectThrows(
runCommandForced( ParameterException.class,
String.format("--renew_billing_cost_transitions=%s=US42", START_OF_TIME), "xn--q9jyb4c"); () ->
runCommandForced(
String.format("--renew_billing_cost_transitions=%s=US42", START_OF_TIME),
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
} }
@Test @Test
public void testFailure_negativeRenewBillingCost() throws Exception { public void testFailure_negativeRenewBillingCost() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Renew billing cost cannot be negative"); expectThrows(
runCommandForced( IllegalArgumentException.class,
String.format("--renew_billing_cost_transitions=%s=USD-42", START_OF_TIME), () ->
"xn--q9jyb4c"); runCommandForced(
String.format("--renew_billing_cost_transitions=%s=USD-42", START_OF_TIME),
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Renew billing cost cannot be negative");
} }
@Test @Test
public void testFailure_invalidRenewCostTransitionTime() throws Exception { public void testFailure_invalidRenewCostTransitionTime() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("not formatted correctly or has transition times out of order"); expectThrows(
runCommandForced("--renew_billing_cost_transitions=tomorrow=USD 1", "xn--q9jyb4c"); ParameterException.class,
() ->
runCommandForced("--renew_billing_cost_transitions=tomorrow=USD 1", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
} }
@Test @Test
public void testFailure_duplicateRenewCostTransitionTimes() throws Exception { public void testFailure_duplicateRenewCostTransitionTimes() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("not formatted correctly or has transition times out of order"); expectThrows(
runCommandForced( ParameterException.class,
String.format("--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"", now, now), () ->
"xn--q9jyb4c"); runCommandForced(
String.format(
"--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"", now, now),
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
} }
@Test @Test
public void testFailure_outOfOrderRenewCostTransitionTimes() throws Exception { public void testFailure_outOfOrderRenewCostTransitionTimes() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("not formatted correctly or has transition times out of order"); expectThrows(
runCommandForced( ParameterException.class,
String.format( () ->
"--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"", runCommandForced(
now, now.minus(Duration.millis(1))), String.format(
"xn--q9jyb4c"); "--renew_billing_cost_transitions=\"%s=USD 1,%s=USD 2\"",
now, now.minus(Duration.millis(1))),
"xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("not formatted correctly or has transition times out of order");
} }
@Test @Test
public void testFailure_noTldName() throws Exception { public void testFailure_noTldName() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown = expectThrows(ParameterException.class, () -> runCommandForced());
thrown.expectMessage("Main parameters are required (\"Names of the TLDs\")"); assertThat(thrown)
runCommandForced(); .hasMessageThat()
.contains("Main parameters are required (\"Names of the TLDs\")");
} }
@Test @Test
public void testFailure_oneTldDoesNotExist() throws Exception { public void testFailure_oneTldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("TLD foo does not exist"); expectThrows(IllegalArgumentException.class, () -> runCommandForced("foo", "xn--q9jyb4c"));
runCommandForced("foo", "xn--q9jyb4c"); assertThat(thrown).hasMessageThat().contains("TLD foo does not exist");
} }
@Test @Test
public void testFailure_duplicateArguments() throws Exception { public void testFailure_duplicateArguments() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Duplicate arguments found: 'xn--q9jyb4c'"); expectThrows(
runCommandForced("xn--q9jyb4c", "xn--q9jyb4c"); IllegalArgumentException.class, () -> runCommandForced("xn--q9jyb4c", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("Duplicate arguments found: 'xn--q9jyb4c'");
} }
@Test @Test
public void testFailure_tldDoesNotExist() throws Exception { public void testFailure_tldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("TLD foobarbaz does not exist"); expectThrows(IllegalArgumentException.class, () -> runCommandForced("foobarbaz"));
runCommandForced("foobarbaz"); assertThat(thrown).hasMessageThat().contains("TLD foobarbaz does not exist");
} }
@Test @Test
public void testFailure_specifiedDnsWriter_doesntExist() throws Exception { public void testFailure_specifiedDnsWriter_doesntExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Invalid DNS writer name(s) specified: [InvalidDnsWriter]"); expectThrows(
runCommandForced("xn--q9jyb4c", "--dns_writers=InvalidDnsWriter"); IllegalArgumentException.class,
() -> runCommandForced("xn--q9jyb4c", "--dns_writers=InvalidDnsWriter"));
assertThat(thrown)
.hasMessageThat()
.contains("Invalid DNS writer name(s) specified: [InvalidDnsWriter]");
} }
@Test @Test
public void testFailure_setNonExistentReservedLists() throws Exception { public void testFailure_setNonExistentReservedLists() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Could not find reserved list xn--q9jyb4c_ZZZ to add to the tld"); expectThrows(
runCommandForced("--reserved_lists", "xn--q9jyb4c_ZZZ", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--reserved_lists", "xn--q9jyb4c_ZZZ", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains("Could not find reserved list xn--q9jyb4c_ZZZ to add to the tld");
} }
@Test @Test
@ -686,9 +772,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
persistResource(Registry.get("xn--q9jyb4c").asBuilder() persistResource(Registry.get("xn--q9jyb4c").asBuilder()
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"))
.build()); .build());
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("xn--q9jyb4c_r1"); expectThrows(
runCommandForced("--add_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--add_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("xn--q9jyb4c_r1");
} }
@Test @Test
@ -696,19 +784,24 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
persistResource(Registry.get("xn--q9jyb4c").asBuilder() persistResource(Registry.get("xn--q9jyb4c").asBuilder()
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"))
.build()); .build());
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("xn--q9jyb4c_Z"); expectThrows(
runCommandForced("--remove_reserved_lists=xn--q9jyb4c_Z", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--remove_reserved_lists=xn--q9jyb4c_Z", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("xn--q9jyb4c_Z");
} }
@Test @Test
public void testFailure_cantAddAndRemoveSameReservedListSimultaneously() throws Exception { public void testFailure_cantAddAndRemoveSameReservedListSimultaneously() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("xn--q9jyb4c_r1"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--add_reserved_lists=xn--q9jyb4c_r1", () ->
"--remove_reserved_lists=xn--q9jyb4c_r1", runCommandForced(
"xn--q9jyb4c"); "--add_reserved_lists=xn--q9jyb4c_r1",
"--remove_reserved_lists=xn--q9jyb4c_r1",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("xn--q9jyb4c_r1");
} }
@Test @Test
@ -717,9 +810,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
Registry.get("xn--q9jyb4c").asBuilder() Registry.get("xn--q9jyb4c").asBuilder()
.setAllowedRegistrantContactIds(ImmutableSet.of("alice", "bob")) .setAllowedRegistrantContactIds(ImmutableSet.of("alice", "bob"))
.build()); .build());
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("alice"); expectThrows(
runCommandForced("--add_allowed_registrants=alice", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--add_allowed_registrants=alice", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("alice");
} }
@Test @Test
@ -728,19 +823,24 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
Registry.get("xn--q9jyb4c").asBuilder() Registry.get("xn--q9jyb4c").asBuilder()
.setAllowedRegistrantContactIds(ImmutableSet.of("alice")) .setAllowedRegistrantContactIds(ImmutableSet.of("alice"))
.build()); .build());
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("bob"); expectThrows(
runCommandForced("--remove_allowed_registrants=bob", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--remove_allowed_registrants=bob", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("bob");
} }
@Test @Test
public void testFailure_cantAddAndRemoveSameAllowedRegistrantsSimultaneously() throws Exception { public void testFailure_cantAddAndRemoveSameAllowedRegistrantsSimultaneously() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("alice"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--add_allowed_registrants=alice", () ->
"--remove_allowed_registrants=alice", runCommandForced(
"xn--q9jyb4c"); "--add_allowed_registrants=alice",
"--remove_allowed_registrants=alice",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("alice");
} }
@Test @Test
@ -750,9 +850,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.setAllowedFullyQualifiedHostNames( .setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns1.example.com", "ns2.example.com")) ImmutableSet.of("ns1.example.com", "ns2.example.com"))
.build()); .build());
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("ns1.example.com"); expectThrows(
runCommandForced("--add_allowed_nameservers=ns1.example.com", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--add_allowed_nameservers=ns1.example.com", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("ns1.example.com");
} }
@Test @Test
@ -762,19 +864,24 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.setAllowedFullyQualifiedHostNames( .setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns1.example.com")) ImmutableSet.of("ns1.example.com"))
.build()); .build());
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("ns2.example.com"); expectThrows(
runCommandForced("--remove_allowed_nameservers=ns2.example.com", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--remove_allowed_nameservers=ns2.example.com", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("ns2.example.com");
} }
@Test @Test
public void testFailure_cantAddAndRemoveSameAllowedNameserversSimultaneously() throws Exception { public void testFailure_cantAddAndRemoveSameAllowedNameserversSimultaneously() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("ns1.example.com"); expectThrows(
runCommandForced( IllegalArgumentException.class,
"--add_allowed_nameservers=ns1.example.com", () ->
"--remove_allowed_nameservers=ns1.example.com", runCommandForced(
"xn--q9jyb4c"); "--add_allowed_nameservers=ns1.example.com",
"--remove_allowed_nameservers=ns1.example.com",
"xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("ns1.example.com");
} }
@Test @Test
@ -895,9 +1002,11 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
@Test @Test
public void testFailure_setPremiumListThatDoesntExist() throws Exception { public void testFailure_setPremiumListThatDoesntExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("The premium list 'phonies' doesn't exist"); expectThrows(
runCommandForced("--premium_list=phonies", "xn--q9jyb4c"); IllegalArgumentException.class,
() -> runCommandForced("--premium_list=phonies", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("The premium list 'phonies' doesn't exist");
} }
@Test @Test
@ -910,17 +1019,24 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
@Test @Test
public void testFailure_updateLrpPeriod_backwardsInterval() throws Exception { public void testFailure_updateLrpPeriod_backwardsInterval() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage( expectThrows(
"--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z not an ISO-8601 interval"); ParameterException.class,
runCommandForced("--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z", "xn--q9jyb4c"); () ->
runCommandForced(
"--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z", "xn--q9jyb4c"));
assertThat(thrown)
.hasMessageThat()
.contains(
"--lrp_period=2005-06-09T12:30:00Z/2004-07-10T13:30:00Z not an ISO-8601 interval");
} }
@Test @Test
public void testFailure_updateLrpPeriod_badInterval() throws Exception { public void testFailure_updateLrpPeriod_badInterval() throws Exception {
thrown.expect(ParameterException.class); ParameterException thrown =
thrown.expectMessage("--lrp_period=foobar not an ISO-8601 interval"); expectThrows(
runCommandForced("--lrp_period=foobar", "xn--q9jyb4c"); ParameterException.class, () -> runCommandForced("--lrp_period=foobar", "xn--q9jyb4c"));
assertThat(thrown).hasMessageThat().contains("--lrp_period=foobar not an ISO-8601 interval");
} }
private void runSuccessfulReservedListsTest(String reservedLists) throws Exception { private void runSuccessfulReservedListsTest(String reservedLists) throws Exception {

View file

@ -15,6 +15,7 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.assertThrows;
import google.registry.model.tmch.ClaimsListShard; import google.registry.model.tmch.ClaimsListShard;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -52,8 +53,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase<UploadClaimsLis
"example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z",
"another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z",
"anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z");
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename));
runCommand("--force", filename);
} }
@Test @Test
@ -64,8 +64,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase<UploadClaimsLis
"example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z",
"another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z",
"anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z");
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename));
runCommand("--force", filename);
} }
@Test @Test
@ -76,8 +75,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase<UploadClaimsLis
"example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z",
"another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z",
"anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z");
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename));
runCommand("--force", filename);
} }
@Test @Test
@ -88,8 +86,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase<UploadClaimsLis
"example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z",
"another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z",
"anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z");
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename));
runCommand("--force", filename);
} }
@Test @Test
@ -100,8 +97,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase<UploadClaimsLis
"example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z",
"another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z",
"anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z");
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename));
runCommand("--force", filename);
} }
@Test @Test
@ -112,8 +108,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase<UploadClaimsLis
"example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z",
"another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z",
"anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z");
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename));
runCommand("--force", filename);
} }
@Test @Test
@ -124,8 +119,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase<UploadClaimsLis
"example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z",
"another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z",
"anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z");
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename));
runCommand("--force", filename);
} }
@Test @Test
@ -136,8 +130,7 @@ public class UploadClaimsListCommandTest extends CommandTestCase<UploadClaimsLis
"example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z,extra", "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z,extra",
"another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z", "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,2012-08-16T00:00:00.0Z",
"anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z");
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename));
runCommand("--force", filename);
} }
@Test @Test
@ -148,25 +141,21 @@ public class UploadClaimsListCommandTest extends CommandTestCase<UploadClaimsLis
"example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z", "example,2013041500/2/6/9/rJ1NrDO92vDsAzf7EQzgjX4R0000000001,2010-07-14T00:00:00.0Z",
"another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,foo", "another-example,2013041500/6/A/5/alJAqG2vI2BmCv5PfUvuDkf40000000002,foo",
"anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z"); "anotherexample,2013041500/A/C/7/rHdC4wnrWRvPY6nneCVtQhFj0000000003,2011-08-16T12:00:00.0Z");
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", filename));
runCommand("--force", filename);
} }
@Test @Test
public void testFailure_fileDoesNotExist() throws Exception { public void testFailure_fileDoesNotExist() throws Exception {
thrown.expect(FileNotFoundException.class); assertThrows(FileNotFoundException.class, () -> runCommand("--force", "nonexistent_file.csv"));
runCommand("--force", "nonexistent_file.csv");
} }
@Test @Test
public void testFailure_noFileNamePassed() throws Exception { public void testFailure_noFileNamePassed() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--force"));
runCommand("--force");
} }
@Test @Test
public void testFailure_tooManyArguments() throws Exception { public void testFailure_tooManyArguments() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(IllegalArgumentException.class, () -> runCommand("--force", "foo", "bar"));
runCommand("--force", "foo", "bar");
} }
} }

View file

@ -15,6 +15,7 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.rde.RdeTestData; import google.registry.rde.RdeTestData;
import google.registry.xml.XmlException; import google.registry.xml.XmlException;
@ -101,9 +102,11 @@ public class ValidateEscrowDepositCommandTest
@Test @Test
public void testRun_badXml() throws Exception { public void testRun_badXml() throws Exception {
String file = writeToTmpFile(RdeTestData.loadFile("deposit_full.xml").substring(0, 2000)); String file = writeToTmpFile(RdeTestData.loadFile("deposit_full.xml").substring(0, 2000));
thrown.expect(XmlException.class); XmlException thrown = expectThrows(XmlException.class, () -> runCommand("--input=" + file));
thrown.expectMessage("Syntax error at line 46, column 38: " assertThat(thrown)
+ "XML document structures must start and end within the same entity."); .hasMessageThat()
runCommand("--input=" + file); .contains(
"Syntax error at line 46, column 38: "
+ "XML document structures must start and end within the same entity.");
} }
} }

View file

@ -18,6 +18,7 @@ import static google.registry.model.registrar.Registrar.State.ACTIVE;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -62,71 +63,81 @@ public class ValidateLoginCredentialsCommandTest
@Test @Test
public void testFailure_loginWithBadPassword() throws Exception { public void testFailure_loginWithBadPassword() throws Exception {
thrown.expect(BadRegistrarPasswordException.class); assertThrows(
runCommand( BadRegistrarPasswordException.class,
"--client=NewRegistrar", () ->
"--password=" + new StringBuffer(PASSWORD).reverse(), runCommand(
"--cert_hash=" + CERT_HASH, "--client=NewRegistrar",
"--ip_address=" + CLIENT_IP); "--password=" + new StringBuilder(PASSWORD).reverse(),
"--cert_hash=" + CERT_HASH,
"--ip_address=" + CLIENT_IP));
} }
@Test @Test
public void testFailure_loginWithBadCertificateHash() throws Exception { public void testFailure_loginWithBadCertificateHash() throws Exception {
thrown.expect(EppException.class); assertThrows(
runCommand( EppException.class,
"--client=NewRegistrar", () ->
"--password=" + PASSWORD, runCommand(
"--cert_hash=" + new StringBuffer(CERT_HASH).reverse(), "--client=NewRegistrar",
"--ip_address=" + CLIENT_IP); "--password=" + PASSWORD,
"--cert_hash=" + new StringBuilder(CERT_HASH).reverse(),
"--ip_address=" + CLIENT_IP));
} }
@Test @Test
public void testFailure_loginWithBadIp() throws Exception { public void testFailure_loginWithBadIp() throws Exception {
thrown.expect(EppException.class); assertThrows(
runCommand( EppException.class,
"--client=NewRegistrar", () ->
"--password=" + PASSWORD, runCommand(
"--cert_hash=" + CERT_HASH, "--client=NewRegistrar",
"--ip_address=" + new StringBuffer(CLIENT_IP).reverse()); "--password=" + PASSWORD,
"--cert_hash=" + CERT_HASH,
"--ip_address=" + new StringBuilder(CLIENT_IP).reverse()));
} }
@Test @Test
public void testFailure_missingClientId() throws Exception { public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand( ParameterException.class,
"--password=" + PASSWORD, () ->
"--cert_hash=" + CERT_HASH, runCommand(
"--ip_address=" + CLIENT_IP); "--password=" + PASSWORD, "--cert_hash=" + CERT_HASH, "--ip_address=" + CLIENT_IP));
} }
@Test @Test
public void testFailure_missingPassword() throws Exception { public void testFailure_missingPassword() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand( ParameterException.class,
"--client=NewRegistrar", () ->
"--cert_hash=" + CERT_HASH, runCommand(
"--ip_address=" + CLIENT_IP); "--client=NewRegistrar", "--cert_hash=" + CERT_HASH, "--ip_address=" + CLIENT_IP));
} }
@Test @Test
public void testFailure_unknownFlag() throws Exception { public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class); assertThrows(
runCommand( ParameterException.class,
"--client=NewRegistrar", () ->
"--password=" + PASSWORD, runCommand(
"--cert_hash=" + CERT_HASH, "--client=NewRegistrar",
"--ip_address=" + CLIENT_IP, "--password=" + PASSWORD,
"--unrecognized_flag=foo"); "--cert_hash=" + CERT_HASH,
"--ip_address=" + CLIENT_IP,
"--unrecognized_flag=foo"));
} }
@Test @Test
public void testFailure_certHashAndCertFile() throws Exception { public void testFailure_certHashAndCertFile() throws Exception {
thrown.expect(IllegalArgumentException.class); assertThrows(
runCommand( IllegalArgumentException.class,
"--client=NewRegistrar", () ->
"--password=" + PASSWORD, runCommand(
"--cert_hash=" + CERT_HASH, "--client=NewRegistrar",
"--cert_file=" + tmpDir.newFile(), "--password=" + PASSWORD,
"--ip_address=" + CLIENT_IP); "--cert_hash=" + CERT_HASH,
"--cert_file=" + tmpDir.newFile(),
"--ip_address=" + CLIENT_IP));
} }
} }

View file

@ -14,8 +14,10 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.loadRegistrar; import static google.registry.testing.DatastoreHelper.loadRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.mockito.Matchers.anyMapOf; import static org.mockito.Matchers.anyMapOf;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
@ -66,16 +68,17 @@ public class VerifyOteCommandTest extends CommandTestCase<VerifyOteCommand> {
@Test @Test
public void testFailure_registrarDoesntExist() throws Exception { public void testFailure_registrarDoesntExist() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage("Registrar blobio does not exist."); expectThrows(IllegalArgumentException.class, () -> runCommand("blobio"));
runCommand("blobio"); assertThat(thrown).hasMessageThat().contains("Registrar blobio does not exist.");
} }
@Test @Test
public void testFailure_noRegistrarsNoCheckAll() throws Exception { public void testFailure_noRegistrarsNoCheckAll() throws Exception {
thrown.expect(IllegalArgumentException.class); IllegalArgumentException thrown =
thrown.expectMessage( expectThrows(IllegalArgumentException.class, () -> runCommand(""));
"Must provide at least one registrar name, or supply --check-all with no names."); assertThat(thrown)
runCommand(""); .hasMessageThat()
.contains("Must provide at least one registrar name, or supply --check-all with no names.");
} }
} }