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.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -53,9 +52,6 @@ public class EppCommitLogsTest extends ShardableTestCase {
.withTaskQueue()
.build();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule
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 google.registry.flows.EppXmlTransformer.unmarshal;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.ResourceUtils.readResourceBytes;
import google.registry.model.eppinput.EppInput;
import google.registry.model.eppoutput.EppOutput;
import google.registry.testing.ShardableTestCase;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -32,9 +31,6 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class EppXmlTransformerTest extends ShardableTestCase {
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void testUnmarshalingEppInput() throws Exception {
EppInput input = unmarshal(
@ -44,8 +40,11 @@ public class EppXmlTransformerTest extends ShardableTestCase {
@Test
public void testUnmarshalingWrongClassThrows() throws Exception {
thrown.expect(ClassCastException.class);
assertThrows(
ClassCastException.class,
() ->
EppXmlTransformer.unmarshal(
EppOutput.class, readResourceBytes(getClass(), "testdata/contact_info.xml").read());
EppOutput.class,
readResourceBytes(getClass(), "testdata/contact_info.xml").read()));
}
}

View file

@ -15,6 +15,7 @@
package google.registry.flows;
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.ImmutableSet;
@ -38,7 +39,6 @@ import java.util.logging.LogRecord;
import java.util.logging.Logger;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -50,10 +50,6 @@ public class ExtensionManagerTest {
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Test
public void testDuplicateExtensionsForbidden() throws Exception {
ExtensionManager manager = new TestInstanceBuilder()
@ -65,8 +61,7 @@ public class ExtensionManagerTest {
MetadataExtension.class)
.build();
manager.register(MetadataExtension.class, LaunchCreateExtension.class);
thrown.expect(UnsupportedRepeatedExtensionException.class);
manager.validate();
assertThrows(UnsupportedRepeatedExtensionException.class, () -> manager.validate());
}
@Test
@ -97,8 +92,7 @@ public class ExtensionManagerTest {
.setSuppliedExtensions(FeeInfoCommandExtensionV06.class)
.build();
manager.register(FeeInfoCommandExtensionV06.class);
thrown.expect(UndeclaredServiceExtensionException.class);
manager.validate();
assertThrows(UndeclaredServiceExtensionException.class, () -> manager.validate());
}
@Test
@ -131,8 +125,7 @@ public class ExtensionManagerTest {
.setSuppliedExtensions(MetadataExtension.class)
.build();
manager.register(MetadataExtension.class);
thrown.expect(OnlyToolCanPassMetadataException.class);
manager.validate();
assertThrows(OnlyToolCanPassMetadataException.class, () -> manager.validate());
}
@Test
@ -156,8 +149,7 @@ public class ExtensionManagerTest {
.setIsSuperuser(false)
.build();
manager.register(DomainTransferRequestSuperuserExtension.class);
thrown.expect(UnauthorizedForSuperuserExtensionException.class);
manager.validate();
assertThrows(UnauthorizedForSuperuserExtensionException.class, () -> manager.validate());
}
@Test
@ -169,8 +161,7 @@ public class ExtensionManagerTest {
.setIsSuperuser(true)
.build();
manager.register(DomainTransferRequestSuperuserExtension.class);
thrown.expect(UnauthorizedForSuperuserExtensionException.class);
manager.validate();
assertThrows(UnauthorizedForSuperuserExtensionException.class, () -> manager.validate());
}
@Test
@ -180,8 +171,7 @@ public class ExtensionManagerTest {
.setDeclaredUris()
.setSuppliedExtensions(LaunchCreateExtension.class)
.build();
thrown.expect(UnimplementedExtensionException.class);
manager.validate();
assertThrows(UnimplementedExtensionException.class, () -> manager.validate());
}
/** 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.junit.Before;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -87,9 +86,6 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
.withTaskQueue()
.build();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule
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.ofy.ObjectifyService.ofy;
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.TaskQueueHelper.assertTasksEnqueued;
@ -131,8 +132,7 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
@Test
public void testRequiresLogin() throws Exception {
sessionMetadata.setClientId(null);
thrown.expect(NotLoggedInException.class);
runFlow();
assertThrows(NotLoggedInException.class, () -> runFlow());
}
/**

View file

@ -15,37 +15,34 @@
package google.registry.flows;
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.when;
import google.registry.request.HttpException.BadRequestException;
import javax.servlet.http.HttpServletRequest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Unit tests for {@link TlsCredentials}. */
@RunWith(JUnit4.class)
public final class TlsCredentialsTest {
@Rule public final ExpectedException thrown = ExpectedException.none();
@Test
public void testProvideClientCertificateHash() {
HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getHeader("X-SSL-Certificate")).thenReturn("data");
assertThat(TlsCredentials.EppTlsModule.provideClientCertificateHash(req))
.isEqualTo("data");
assertThat(TlsCredentials.EppTlsModule.provideClientCertificateHash(req)).isEqualTo("data");
}
@Test
public void testProvideClientCertificateHash_missing() {
thrown.expect(BadRequestException.class);
thrown.expectMessage("Missing header: X-SSL-Certificate");
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
@ -58,10 +55,12 @@ public final class TlsCredentialsTest {
@Test
public void testProvideRequestedServername_missing() {
thrown.expect(BadRequestException.class);
thrown.expectMessage("Missing header: X-Requested-Servername-SNI");
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.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact;
import static google.registry.testing.JUnitBackports.assertThrows;
import google.registry.flows.ResourceCheckFlowTestCase;
import google.registry.flows.exceptions.TooManyResourceChecksException;
@ -76,8 +77,7 @@ public class ContactCheckFlowTest
@Test
public void testTooManyIds() throws Exception {
setEppInput("contact_check_51.xml");
thrown.expect(TooManyResourceChecksException.class);
runFlow();
assertThrows(TooManyResourceChecksException.class, () -> runFlow());
}
@Test

View file

@ -14,10 +14,13 @@
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.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
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.contact.ContactFlowUtils.BadInternationalizedPostalInfoException;
@ -66,10 +69,12 @@ public class ContactCreateFlowTest
@Test
public void testFailure_alreadyExists() throws Exception {
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(ResourceAlreadyExistsException.class);
thrown.expectMessage(
ResourceAlreadyExistsException thrown =
expectThrows(ResourceAlreadyExistsException.class, () -> runFlow());
assertThat(thrown)
.hasMessageThat()
.contains(
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
runFlow();
}
@Test
@ -81,15 +86,13 @@ public class ContactCreateFlowTest
@Test
public void testFailure_nonAsciiInIntAddress() throws Exception {
setEppInput("contact_create_hebrew_int.xml");
thrown.expect(BadInternationalizedPostalInfoException.class);
runFlow();
assertThrows(BadInternationalizedPostalInfoException.class, () -> runFlow());
}
@Test
public void testFailure_declineDisclosure() throws Exception {
setEppInput("contact_create_decline_disclosure.xml");
thrown.expect(DeclineContactDisclosureFieldDisallowedPolicyException.class);
runFlow();
assertThrows(DeclineContactDisclosureFieldDisallowedPolicyException.class, () -> runFlow());
}
@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.persistDeletedContact;
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.ImmutableSet;
@ -71,17 +72,17 @@ public class ContactDeleteFlowTest
@Test
public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -116,8 +117,7 @@ public class ContactDeleteFlowTest
public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
@ -142,8 +142,7 @@ public class ContactDeleteFlowTest
createTld("tld");
persistResource(
newDomainResource("example.tld", persistActiveContact(getUniqueIdFromCommand())));
thrown.expect(ResourceToDeleteIsReferencedException.class);
runFlow();
assertThrows(ResourceToDeleteIsReferencedException.class, () -> runFlow());
}
@Test
@ -151,8 +150,7 @@ public class ContactDeleteFlowTest
createTld("tld");
persistResource(
newDomainResource("example.tld", persistActiveContact(getUniqueIdFromCommand())));
thrown.expect(ResourceToDeleteIsReferencedException.class);
runFlow();
assertThrows(ResourceToDeleteIsReferencedException.class, () -> runFlow());
}
@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.newDomainResource;
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.ImmutableSet;
@ -163,17 +164,17 @@ public class ContactInfoFlowTest extends ResourceFlowTestCase<ContactInfoFlow, C
@Test
public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistContactResource(false);
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test

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.getPollMessages;
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.ResourceDoesNotExistException;
@ -142,73 +144,76 @@ public class ContactTransferApproveFlowTest
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_approve_with_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_approve_with_authinfo.xml"));
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
}
@Test
public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
}
@Test
public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
}
@Test
public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
}
@Test
public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
}
@Test
public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_approve.xml"));
}
@Test
public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("contact_transfer_approve.xml");
assertThrows(
ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_approve.xml"));
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("contact_transfer_approve.xml");
assertThrows(
ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_approve.xml"));
}
@Test
public void testFailure_deletedContact() throws Exception {
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("contact_transfer_approve.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_approve.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -216,9 +221,11 @@ public class ContactTransferApproveFlowTest
deleteResource(contact);
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("contact_transfer_approve.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_approve.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@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.getPollMessages;
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.ResourceDoesNotExistException;
@ -126,81 +128,86 @@ public class ContactTransferCancelFlowTest
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_cancel_with_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_cancel_with_authinfo.xml"));
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
}
@Test
public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
}
@Test
public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
}
@Test
public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
}
@Test
public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
}
@Test
public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
}
@Test
public void testFailure_sponsoringClient() throws Exception {
setClientIdForFlow("TheRegistrar");
thrown.expect(NotTransferInitiatorException.class);
doFailingTest("contact_transfer_cancel.xml");
assertThrows(
NotTransferInitiatorException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
thrown.expect(NotTransferInitiatorException.class);
doFailingTest("contact_transfer_cancel.xml");
assertThrows(
NotTransferInitiatorException.class, () -> doFailingTest("contact_transfer_cancel.xml"));
}
@Test
public void testFailure_deletedContact() throws Exception {
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("contact_transfer_cancel.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_cancel.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact);
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("contact_transfer_cancel.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_cancel.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test

View file

@ -14,10 +14,13 @@
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.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.deleteResource;
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.ResourceDoesNotExistException;
@ -138,8 +141,9 @@ public class ContactTransferQueryFlowTest
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_query_with_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_query_with_authinfo.xml"));
}
@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
// code above will write the wrong ROID into the file.
contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build();
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_query_with_roid.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_query_with_roid.xml"));
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
thrown.expect(NoTransferHistoryToQueryException.class);
doFailingTest("contact_transfer_query.xml");
assertThrows(
NoTransferHistoryToQueryException.class, () -> doFailingTest("contact_transfer_query.xml"));
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
thrown.expect(NotAuthorizedToViewTransferException.class);
doFailingTest("contact_transfer_query.xml");
assertThrows(
NotAuthorizedToViewTransferException.class,
() -> doFailingTest("contact_transfer_query.xml"));
}
@Test
public void testFailure_deletedContact() throws Exception {
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("contact_transfer_query.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("contact_transfer_query.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact);
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("contact_transfer_query.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("contact_transfer_query.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@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.getPollMessages;
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.ResourceDoesNotExistException;
@ -141,81 +143,86 @@ public class ContactTransferRejectFlowTest
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_reject_with_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("contact_transfer_reject_with_authinfo.xml"));
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
}
@Test
public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
}
@Test
public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
}
@Test
public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
}
@Test
public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
}
@Test
public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("contact_transfer_reject.xml"));
}
@Test
public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("contact_transfer_reject.xml");
assertThrows(
ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_reject.xml"));
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("contact_transfer_reject.xml");
assertThrows(
ResourceNotOwnedException.class, () -> doFailingTest("contact_transfer_reject.xml"));
}
@Test
public void testFailure_deletedContact() throws Exception {
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("contact_transfer_reject.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_reject.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact);
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("contact_transfer_reject.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_reject.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@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.persistActiveContact;
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.Iterables;
@ -154,8 +156,9 @@ public class ContactTransferRequestFlowTest
@Test
public void testFailure_noAuthInfo() throws Exception {
thrown.expect(MissingTransferRequestAuthInfoException.class);
doFailingTest("contact_transfer_request_no_authinfo.xml");
assertThrows(
MissingTransferRequestAuthInfoException.class,
() -> doFailingTest("contact_transfer_request_no_authinfo.xml"));
}
@Test
@ -165,8 +168,8 @@ public class ContactTransferRequestFlowTest
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_request.xml");
assertThrows(
BadAuthInfoForResourceException.class, () -> doFailingTest("contact_transfer_request.xml"));
}
@Test
@ -208,59 +211,69 @@ public class ContactTransferRequestFlowTest
.setPendingTransferExpirationTime(clock.nowUtc().plusDays(1))
.build())
.build());
thrown.expect(AlreadyPendingTransferException.class);
doFailingTest("contact_transfer_request.xml");
assertThrows(
AlreadyPendingTransferException.class, () -> doFailingTest("contact_transfer_request.xml"));
}
@Test
public void testFailure_sponsoringClient() throws Exception {
setClientIdForFlow("TheRegistrar");
thrown.expect(ObjectAlreadySponsoredException.class);
doFailingTest("contact_transfer_request.xml");
assertThrows(
ObjectAlreadySponsoredException.class, () -> doFailingTest("contact_transfer_request.xml"));
}
@Test
public void testFailure_deletedContact() throws Exception {
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("contact_transfer_request.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact);
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("contact_transfer_request.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_clientTransferProhibited() throws Exception {
contact = persistResource(
contact.asBuilder().addStatusValue(StatusValue.CLIENT_TRANSFER_PROHIBITED).build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("clientTransferProhibited");
doFailingTest("contact_transfer_request.xml");
ResourceStatusProhibitsOperationException thrown =
expectThrows(
ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("clientTransferProhibited");
}
@Test
public void testFailure_serverTransferProhibited() throws Exception {
contact = persistResource(
contact.asBuilder().addStatusValue(StatusValue.SERVER_TRANSFER_PROHIBITED).build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("serverTransferProhibited");
doFailingTest("contact_transfer_request.xml");
ResourceStatusProhibitsOperationException thrown =
expectThrows(
ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("serverTransferProhibited");
}
@Test
public void testFailure_pendingDelete() throws Exception {
contact = persistResource(
contact.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("pendingDelete");
doFailingTest("contact_transfer_request.xml");
ResourceStatusProhibitsOperationException thrown =
expectThrows(
ResourceStatusProhibitsOperationException.class,
() -> doFailingTest("contact_transfer_request.xml"));
assertThat(thrown).hasMessageThat().contains("pendingDelete");
}
@Test

View file

@ -14,12 +14,15 @@
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.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.newContactResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistDeletedContact;
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.ImmutableSet;
@ -253,25 +256,24 @@ public class ContactUpdateFlowTest
@Test
public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_statusValueNotClientSettable() throws Exception {
setEppInput("contact_update_prohibited_status.xml");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(StatusNotClientSettableException.class);
runFlow();
assertThrows(StatusNotClientSettableException.class, () -> runFlow());
}
@Test
@ -289,8 +291,7 @@ public class ContactUpdateFlowTest
public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
@ -337,8 +338,7 @@ public class ContactUpdateFlowTest
newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build());
thrown.expect(ResourceHasClientUpdateProhibitedException.class);
runFlow();
assertThrows(ResourceHasClientUpdateProhibitedException.class, () -> runFlow());
}
@Test
@ -347,9 +347,9 @@ public class ContactUpdateFlowTest
newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED))
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("serverUpdateProhibited");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited");
}
@Test
@ -358,9 +358,9 @@ public class ContactUpdateFlowTest
newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("pendingDelete");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("pendingDelete");
}
@Test
@ -373,24 +373,21 @@ public class ContactUpdateFlowTest
public void testFailure_nonAsciiInIntAddress() throws Exception {
setEppInput("contact_update_hebrew_int.xml");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(BadInternationalizedPostalInfoException.class);
runFlow();
assertThrows(BadInternationalizedPostalInfoException.class, () -> runFlow());
}
@Test
public void testFailure_declineDisclosure() throws Exception {
setEppInput("contact_update_decline_disclosure.xml");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(DeclineContactDisclosureFieldDisallowedPolicyException.class);
runFlow();
assertThrows(DeclineContactDisclosureFieldDisallowedPolicyException.class, () -> runFlow());
}
@Test
public void testFailure_addRemoveSameValue() throws Exception {
setEppInput("contact_update_add_remove_same.xml");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(AddRemoveSameValueException.class);
runFlow();
assertThrows(AddRemoveSameValueException.class, () -> runFlow());
}
@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.DomainApplicationSubject.assertAboutApplications;
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.assertNoDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
@ -253,9 +255,9 @@ public class DomainAllocateFlowTest
.setAllowedRegistrantContactIds(ImmutableSet.of("jd1234"))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net"))
.build());
thrown.expect(NameserversNotAllowedForTldException.class);
thrown.expectMessage("ns1.example.net");
runFlowAsSuperuser();
NameserversNotAllowedForTldException thrown =
expectThrows(NameserversNotAllowedForTldException.class, () -> runFlowAsSuperuser());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -268,9 +270,9 @@ public class DomainAllocateFlowTest
.setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns1.example.net", "ns2.example.net"))
.build());
thrown.expect(RegistrantNotAllowedException.class);
thrown.expectMessage("jd1234");
runFlowAsSuperuser();
RegistrantNotAllowedException thrown =
expectThrows(RegistrantNotAllowedException.class, () -> runFlowAsSuperuser());
assertThat(thrown).hasMessageThat().contains("jd1234");
}
@Test
@ -283,8 +285,9 @@ public class DomainAllocateFlowTest
.setAllowedRegistrantContactIds(ImmutableSet.of("jd1234"))
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.net, ns2.example.net"))
.build());
thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class);
runFlowAsSuperuser();
assertThrows(
NameserversNotSpecifiedForTldWithNameserverWhitelistException.class,
() -> runFlowAsSuperuser());
}
@Test
@ -313,9 +316,9 @@ public class DomainAllocateFlowTest
"reserved",
"example-one,NAMESERVER_RESTRICTED," + "ns2.example.net:ns3.example.net"))
.build());
thrown.expect(NameserversNotAllowedForDomainException.class);
thrown.expectMessage("ns1.example.net");
runFlowAsSuperuser();
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlowAsSuperuser());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -330,8 +333,9 @@ public class DomainAllocateFlowTest
"reserved",
"example-one,NAMESERVER_RESTRICTED," + "ns2.example.net:ns3.example.net"))
.build());
thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class);
runFlowAsSuperuser();
assertThrows(
NameserversNotSpecifiedForNameserverRestrictedDomainException.class,
() -> runFlowAsSuperuser());
}
@Test
@ -366,9 +370,9 @@ public class DomainAllocateFlowTest
.setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns1.example.net", "ns2.example.net", "ns3.example.net"))
.build());
thrown.expect(NameserversNotAllowedForDomainException.class);
thrown.expectMessage("ns1.example.net");
runFlowAsSuperuser();
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlowAsSuperuser());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -385,9 +389,9 @@ public class DomainAllocateFlowTest
.setAllowedFullyQualifiedHostNames(
ImmutableSet.of("ns4.example.net", "ns2.example.net", "ns3.example.net"))
.build());
thrown.expect(NameserversNotAllowedForTldException.class);
thrown.expectMessage("ns1.example.net");
runFlowAsSuperuser();
NameserversNotAllowedForTldException thrown =
expectThrows(NameserversNotAllowedForTldException.class, () -> runFlowAsSuperuser());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -571,8 +575,7 @@ public class DomainAllocateFlowTest
public void testFailure_alreadyExists() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(ResourceAlreadyExistsException.class);
runFlowAsSuperuser();
assertThrows(ResourceAlreadyExistsException.class, () -> runFlowAsSuperuser());
}
@Test
@ -607,8 +610,7 @@ public class DomainAllocateFlowTest
public void testFailure_applicationDeleted() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
persistResource(application.asBuilder().setDeletionTime(clock.nowUtc()).build());
thrown.expect(MissingApplicationException.class);
runFlowAsSuperuser();
assertThrows(MissingApplicationException.class, () -> runFlowAsSuperuser());
}
@Test
@ -617,8 +619,7 @@ public class DomainAllocateFlowTest
persistResource(application.asBuilder()
.setApplicationStatus(ApplicationStatus.REJECTED)
.build());
thrown.expect(HasFinalStatusException.class);
runFlowAsSuperuser();
assertThrows(HasFinalStatusException.class, () -> runFlowAsSuperuser());
}
@Test
@ -627,16 +628,14 @@ public class DomainAllocateFlowTest
persistResource(application.asBuilder()
.setApplicationStatus(ApplicationStatus.ALLOCATED)
.build());
thrown.expect(HasFinalStatusException.class);
runFlowAsSuperuser();
assertThrows(HasFinalStatusException.class, () -> runFlowAsSuperuser());
}
@Test
public void testFailure_applicationDoesNotExist() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
setEppInput("domain_allocate_bad_application_roid.xml");
thrown.expect(MissingApplicationException.class);
runFlowAsSuperuser();
assertThrows(MissingApplicationException.class, () -> runFlowAsSuperuser());
}
@Test
@ -645,16 +644,16 @@ public class DomainAllocateFlowTest
clock.advanceOneMilli();
setEppInput("domain_allocate_no_nameservers.xml");
assertTransactionalFlow(true);
thrown.expect(OnlySuperuserCanAllocateException.class);
runFlow(CommitMode.LIVE, UserPrivileges.NORMAL);
assertThrows(
OnlySuperuserCanAllocateException.class,
() -> runFlow(CommitMode.LIVE, UserPrivileges.NORMAL));
}
@Test
public void testFailure_max10Years() throws Exception {
setupDomainApplication("tld", TldState.QUIET_PERIOD);
setEppInput("domain_allocate_11_years.xml");
thrown.expect(ExceedsMaxRegistrationYearsException.class);
runFlowAsSuperuser();
assertThrows(ExceedsMaxRegistrationYearsException.class, () -> runFlowAsSuperuser());
}
@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.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static java.util.Comparator.comparing;
import static org.joda.money.CurrencyUnit.EUR;
@ -245,8 +246,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_encoded_signed_mark_corrupt.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(SignedMarkParsingErrorException.class);
runFlow();
assertThrows(SignedMarkParsingErrorException.class, () -> runFlow());
}
@Test
@ -255,8 +255,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_encoded_signed_mark_revoked_cert.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(SignedMarkCertificateRevokedException.class);
runFlow();
assertThrows(SignedMarkCertificateRevokedException.class, () -> runFlow());
}
@Test
@ -267,8 +266,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli();
clock.setTo(DateTime.parse("2022-01-01"));
clock.setTo(DateTime.parse("2022-01-01"));
thrown.expect(SignedMarkCertificateExpiredException.class);
runFlow();
assertThrows(SignedMarkCertificateExpiredException.class, () -> runFlow());
}
@Test
@ -278,8 +276,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts();
clock.advanceOneMilli();
clock.setTo(DateTime.parse("2012-07-22T00:01:00Z"));
thrown.expect(SignedMarkCertificateNotYetValidException.class);
runFlow();
assertThrows(SignedMarkCertificateNotYetValidException.class, () -> runFlow());
}
@Test
@ -296,8 +293,7 @@ public class DomainApplicationCreateFlowTest
public void verify(byte[] smdXml) throws GeneralSecurityException {
throw new GeneralSecurityException();
}};
thrown.expect(SignedMarkCertificateInvalidException.class);
runFlow();
assertThrows(SignedMarkCertificateInvalidException.class, () -> runFlow());
}
@Test
@ -307,8 +303,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_encoded_signed_mark.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(SignedMarkCertificateSignatureException.class);
runFlow();
assertThrows(SignedMarkCertificateSignatureException.class, () -> runFlow());
}
@Test
@ -317,8 +312,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_encoded_signed_mark_signature_corrupt.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(SignedMarkSignatureException.class);
runFlow();
assertThrows(SignedMarkSignatureException.class, () -> runFlow());
}
@Test
@ -394,8 +388,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_allowedinsunrise.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(DomainReservedException.class);
runFlow();
assertThrows(DomainReservedException.class, () -> runFlow());
}
@Test
@ -406,8 +399,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli();
// Modify the Registrar to block premium names.
persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build());
thrown.expect(PremiumNameBlockedException.class);
runFlow();
assertThrows(PremiumNameBlockedException.class, () -> runFlow());
}
@Test
@ -416,8 +408,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_premium.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(FeesRequiredForPremiumNameException.class);
runFlow();
assertThrows(FeesRequiredForPremiumNameException.class, () -> runFlow());
}
@Test
@ -526,8 +517,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts();
clock.advanceOneMilli();
setEppInput("domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -537,8 +527,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli();
setEppInput(
"domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -548,8 +537,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli();
setEppInput(
"domain_create_landrush_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -559,8 +547,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli();
setEppInput(
"domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -570,8 +557,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli();
setEppInput(
"domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -581,8 +567,7 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli();
setEppInput(
"domain_create_landrush_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -591,8 +576,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts();
clock.advanceOneMilli();
setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -601,8 +585,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts();
clock.advanceOneMilli();
setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -611,8 +594,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts();
clock.advanceOneMilli();
setEppInput("domain_create_landrush_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -718,8 +700,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_without_marks.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(LandrushApplicationDisallowedDuringSunriseException.class);
runFlow();
assertThrows(LandrushApplicationDisallowedDuringSunriseException.class, () -> runFlow());
}
@Test
@ -734,8 +715,7 @@ public class DomainApplicationCreateFlowTest
.setState(State.SUSPENDED)
.build());
clock.advanceOneMilli();
thrown.expect(RegistrarMustBeActiveToCreateDomainsException.class);
runFlow();
assertThrows(RegistrarMustBeActiveToCreateDomainsException.class, () -> runFlow());
}
@Test
@ -744,8 +724,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_signed_mark.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(SunriseApplicationDisallowedDuringLandrushException.class);
runFlow();
assertThrows(SunriseApplicationDisallowedDuringLandrushException.class, () -> runFlow());
}
@Test
@ -753,8 +732,7 @@ public class DomainApplicationCreateFlowTest
SignedMarkRevocationList.create(clock.nowUtc(), ImmutableMap.of(SMD_ID, clock.nowUtc())).save();
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(SignedMarkRevokedErrorException.class);
runFlow();
assertThrows(SignedMarkRevokedErrorException.class, () -> runFlow());
}
@Test
@ -763,8 +741,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_14_nameservers.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(TooManyNameserversException.class);
runFlow();
assertThrows(TooManyNameserversException.class, () -> runFlow());
}
@Test
@ -772,8 +749,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_with_secdns_maxsiglife.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(MaxSigLifeNotSupportedException.class);
runFlow();
assertThrows(MaxSigLifeNotSupportedException.class, () -> runFlow());
}
@Test
@ -781,8 +757,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_signed_mark_with_secdns_9_records.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(TooManyDsRecordsException.class);
runFlow();
assertThrows(TooManyDsRecordsException.class, () -> runFlow());
}
@Test
@ -790,8 +765,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_wrong_extension.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(UnimplementedExtensionException.class);
runFlow();
assertThrows(UnimplementedExtensionException.class, () -> runFlow());
}
@Test
@ -799,8 +773,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_signed_mark_reserved.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(DomainReservedException.class);
runFlow();
assertThrows(DomainReservedException.class, () -> runFlow());
}
@Test
@ -852,8 +825,7 @@ public class DomainApplicationCreateFlowTest
persistSunriseApplication();
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(UncontestedSunriseApplicationBlockedInLandrushException.class);
runFlow();
assertThrows(UncontestedSunriseApplicationBlockedInLandrushException.class, () -> runFlow());
}
@Test
@ -940,8 +912,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(InvalidLrpTokenException.class);
runFlow();
assertThrows(InvalidLrpTokenException.class, () -> runFlow());
}
@Test
@ -961,8 +932,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(InvalidLrpTokenException.class);
runFlow();
assertThrows(InvalidLrpTokenException.class, () -> runFlow());
}
@Test
@ -981,8 +951,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(InvalidLrpTokenException.class);
runFlow();
assertThrows(InvalidLrpTokenException.class, () -> runFlow());
}
@Test
@ -1037,8 +1006,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(InvalidLrpTokenException.class);
runFlow();
assertThrows(InvalidLrpTokenException.class, () -> runFlow());
}
@Test
@ -1047,8 +1015,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_months.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(BadPeriodUnitException.class);
runFlow();
assertThrows(BadPeriodUnitException.class, () -> runFlow());
}
@Test
@ -1056,9 +1023,9 @@ public class DomainApplicationCreateFlowTest
persistActiveHost("ns1.example.net");
persistActiveContact("jd1234");
persistActiveContact("sh8013");
thrown.expect(LinkedResourcesDoNotExistException.class);
thrown.expectMessage("(ns2.example.net)");
runFlow();
LinkedResourcesDoNotExistException thrown =
expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("(ns2.example.net)");
}
@Test
@ -1066,9 +1033,9 @@ public class DomainApplicationCreateFlowTest
persistActiveHost("ns1.example.net");
persistActiveHost("ns2.example.net");
persistActiveContact("jd1234");
thrown.expect(LinkedResourcesDoNotExistException.class);
thrown.expectMessage("(sh8013)");
runFlow();
LinkedResourcesDoNotExistException thrown =
expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("(sh8013)");
}
@Test
@ -1077,8 +1044,7 @@ public class DomainApplicationCreateFlowTest
createTld("foo", TldState.SUNRISE);
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(TldDoesNotExistException.class);
runFlow();
assertThrows(TldDoesNotExistException.class, () -> runFlow());
}
@Test
@ -1086,8 +1052,7 @@ public class DomainApplicationCreateFlowTest
createTld("tld", TldState.PREDELEGATION);
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
}
@Test
@ -1095,8 +1060,7 @@ public class DomainApplicationCreateFlowTest
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistContactsAndHosts();
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
}
@Test
@ -1104,8 +1068,7 @@ public class DomainApplicationCreateFlowTest
createTld("tld", TldState.SUNRUSH);
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(LaunchPhaseMismatchException.class);
runFlow();
assertThrows(LaunchPhaseMismatchException.class, () -> runFlow());
}
@Test
@ -1113,8 +1076,7 @@ public class DomainApplicationCreateFlowTest
createTld("tld", TldState.QUIET_PERIOD);
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
}
@Test
@ -1122,8 +1084,7 @@ public class DomainApplicationCreateFlowTest
createTld("tld", TldState.GENERAL_AVAILABILITY);
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
}
@Test
@ -1131,8 +1092,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_signed_mark.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(LaunchPhaseMismatchException.class);
runFlow();
assertThrows(LaunchPhaseMismatchException.class, () -> runFlow());
}
@Test
@ -1189,8 +1149,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_duplicate_contact.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(DuplicateContactForRoleException.class);
runFlow();
assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
}
@Test
@ -1199,8 +1158,7 @@ public class DomainApplicationCreateFlowTest
persistContactsAndHosts();
clock.advanceOneMilli();
// We need to test for missing type, but not for invalid - the schema enforces that for us.
thrown.expect(MissingContactTypeException.class);
runFlow();
assertThrows(MissingContactTypeException.class, () -> runFlow());
}
@Test
@ -1208,8 +1166,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_no_matching_marks.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(NoMarksFoundMatchingDomainException.class);
runFlow();
assertThrows(NoMarksFoundMatchingDomainException.class, () -> runFlow());
}
@Test
@ -1218,8 +1175,7 @@ public class DomainApplicationCreateFlowTest
clock.setTo(DateTime.parse("2013-08-09T10:05:59Z").minusSeconds(1));
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(NoMarksFoundMatchingDomainException.class);
runFlow();
assertThrows(NoMarksFoundMatchingDomainException.class, () -> runFlow());
}
@Test
@ -1228,8 +1184,7 @@ public class DomainApplicationCreateFlowTest
clock.setTo(DateTime.parse("2017-07-23T22:00:00.000Z"));
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(NoMarksFoundMatchingDomainException.class);
runFlow();
assertThrows(NoMarksFoundMatchingDomainException.class, () -> runFlow());
}
@Test
@ -1237,8 +1192,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_hex_encoding.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(Base64RequiredForEncodedSignedMarksException.class);
runFlow();
assertThrows(Base64RequiredForEncodedSignedMarksException.class, () -> runFlow());
}
@Test
@ -1246,8 +1200,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_bad_encoding.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(SignedMarkEncodingErrorException.class);
runFlow();
assertThrows(SignedMarkEncodingErrorException.class, () -> runFlow());
}
@Test
@ -1255,8 +1208,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_bad_encoded_xml.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(SignedMarkParsingErrorException.class);
runFlow();
assertThrows(SignedMarkParsingErrorException.class, () -> runFlow());
}
@Test
@ -1265,8 +1217,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_bad_idn_minna.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(InvalidIdnDomainLabelException.class);
runFlow();
assertThrows(InvalidIdnDomainLabelException.class, () -> runFlow());
}
@Test
@ -1276,8 +1227,7 @@ public class DomainApplicationCreateFlowTest
persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY));
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(InvalidTrademarkValidatorException.class);
runFlow();
assertThrows(InvalidTrademarkValidatorException.class, () -> runFlow());
}
@Test
@ -1285,8 +1235,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_signed_mark.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(SignedMarksMustBeEncodedException.class);
runFlow();
assertThrows(SignedMarksMustBeEncodedException.class, () -> runFlow());
}
@Test
@ -1294,8 +1243,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_code_with_mark.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(UnsupportedMarkTypeException.class);
runFlow();
assertThrows(UnsupportedMarkTypeException.class, () -> runFlow());
}
@Test
@ -1303,8 +1251,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_empty_encoded_signed_mark.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(SignedMarkParsingErrorException.class);
runFlow();
assertThrows(SignedMarkParsingErrorException.class, () -> runFlow());
}
@Test
@ -1313,8 +1260,7 @@ public class DomainApplicationCreateFlowTest
persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY));
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(NoticeCannotBeUsedWithSignedMarkException.class);
runFlow();
assertThrows(NoticeCannotBeUsedWithSignedMarkException.class, () -> runFlow());
}
@Test
@ -1322,8 +1268,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_two_signed_marks.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(TooManySignedMarksException.class);
runFlow();
assertThrows(TooManySignedMarksException.class, () -> runFlow());
}
@Test
@ -1333,8 +1278,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(MissingClaimsNoticeException.class);
runFlow();
assertThrows(MissingClaimsNoticeException.class, () -> runFlow());
}
@Test
@ -1343,8 +1287,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_claim_notice.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(UnexpectedClaimsNoticeException.class);
runFlow();
assertThrows(UnexpectedClaimsNoticeException.class, () -> runFlow());
}
@Test
@ -1356,8 +1299,7 @@ public class DomainApplicationCreateFlowTest
persistResource(Registry.get("tld").asBuilder()
.setClaimsPeriodEnd(clock.nowUtc())
.build());
thrown.expect(ClaimsPeriodEndedException.class);
runFlow();
assertThrows(ClaimsPeriodEndedException.class, () -> runFlow());
}
@Test
@ -1368,8 +1310,7 @@ public class DomainApplicationCreateFlowTest
persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY));
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(ExpiredClaimException.class);
runFlow();
assertThrows(ExpiredClaimException.class, () -> runFlow());
}
@Test
@ -1380,8 +1321,7 @@ public class DomainApplicationCreateFlowTest
persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY));
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(AcceptedTooLongAgoException.class);
runFlow();
assertThrows(AcceptedTooLongAgoException.class, () -> runFlow());
}
@Test
@ -1392,8 +1332,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_malformed_claim_notice1.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(MalformedTcnIdException.class);
runFlow();
assertThrows(MalformedTcnIdException.class, () -> runFlow());
}
@Test
@ -1404,8 +1343,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrush_malformed_claim_notice2.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(MalformedTcnIdException.class);
runFlow();
assertThrows(MalformedTcnIdException.class, () -> runFlow());
}
@Test
@ -1416,8 +1354,7 @@ public class DomainApplicationCreateFlowTest
persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY));
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(InvalidTcnIdChecksumException.class);
runFlow();
assertThrows(InvalidTcnIdChecksumException.class, () -> runFlow());
}
@Test
@ -1428,8 +1365,7 @@ public class DomainApplicationCreateFlowTest
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test
@ -1440,8 +1376,7 @@ public class DomainApplicationCreateFlowTest
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test
@ -1452,8 +1387,7 @@ public class DomainApplicationCreateFlowTest
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test
@ -1470,8 +1404,7 @@ public class DomainApplicationCreateFlowTest
.build());
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
@ -1488,8 +1421,7 @@ public class DomainApplicationCreateFlowTest
.build());
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
@ -1506,8 +1438,7 @@ public class DomainApplicationCreateFlowTest
.build());
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
@ -1516,8 +1447,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@Test
@ -1526,8 +1456,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@Test
@ -1536,8 +1465,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@ -1565,9 +1493,9 @@ public class DomainApplicationCreateFlowTest
persistResource(Registry.get("tld").asBuilder()
.setAllowedRegistrantContactIds(ImmutableSet.of("someone"))
.build());
thrown.expect(RegistrantNotAllowedException.class);
thrown.expectMessage("jd1234");
runFlow();
RegistrantNotAllowedException thrown =
expectThrows(RegistrantNotAllowedException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("jd1234");
}
@Test
@ -1576,9 +1504,9 @@ public class DomainApplicationCreateFlowTest
persistResource(Registry.get("tld").asBuilder()
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net"))
.build());
thrown.expect(NameserversNotAllowedForTldException.class);
thrown.expectMessage("ns1.example.net");
runFlow();
NameserversNotAllowedForTldException thrown =
expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -1603,8 +1531,8 @@ public class DomainApplicationCreateFlowTest
.build());
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class);
runFlow();
assertThrows(
NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, () -> runFlow());
}
@Test
@ -1638,9 +1566,9 @@ public class DomainApplicationCreateFlowTest
.build());
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForDomainException.class);
thrown.expectMessage("ns1.example.net");
runFlow();
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -1656,8 +1584,8 @@ public class DomainApplicationCreateFlowTest
.build());
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class);
runFlow();
assertThrows(
NameserversNotSpecifiedForNameserverRestrictedDomainException.class, () -> runFlow());
}
@Test
@ -1697,9 +1625,9 @@ public class DomainApplicationCreateFlowTest
.build());
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForDomainException.class);
thrown.expectMessage("ns1.example.net");
runFlow();
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -1717,9 +1645,9 @@ public class DomainApplicationCreateFlowTest
.build());
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForTldException.class);
thrown.expectMessage("ns1.example.net");
runFlow();
NameserversNotAllowedForTldException thrown =
expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -1728,8 +1656,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_11_years.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(ExceedsMaxRegistrationYearsException.class);
runFlow();
assertThrows(ExceedsMaxRegistrationYearsException.class, () -> runFlow());
}
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.persistActiveDomainApplication;
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.ImmutableMap;
@ -123,9 +125,9 @@ public class DomainApplicationDeleteFlowTest
@Test
public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -134,9 +136,9 @@ public class DomainApplicationDeleteFlowTest
.setRepoId("1-TLD")
.setDeletionTime(clock.nowUtc().minusSeconds(1))
.build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -144,8 +146,7 @@ public class DomainApplicationDeleteFlowTest
sessionMetadata.setClientId("NewRegistrar");
persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
@ -163,8 +164,7 @@ public class DomainApplicationDeleteFlowTest
persistResource(newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
}
@Test
@ -186,8 +186,7 @@ public class DomainApplicationDeleteFlowTest
.setRepoId("1-TLD")
.setPhase(LaunchPhase.SUNRISE)
.build());
thrown.expect(SunriseApplicationCannotBeDeletedInLandrushException.class);
runFlow();
assertThrows(SunriseApplicationCannotBeDeletedInLandrushException.class, () -> runFlow());
}
@Test
@ -233,16 +232,14 @@ public class DomainApplicationDeleteFlowTest
setEppInput("domain_delete_application_landrush.xml", ImmutableMap.of("DOMAIN", "example.tld"));
persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(LaunchPhaseMismatchException.class);
runFlow();
assertThrows(LaunchPhaseMismatchException.class, () -> runFlow());
}
@Test
public void testFailure_wrongExtension() throws Exception {
setEppInput("domain_delete_application_wrong_extension.xml");
persistActiveDomainApplication("example.tld");
thrown.expect(UnimplementedExtensionException.class);
runFlow();
assertThrows(UnimplementedExtensionException.class, () -> runFlow());
}
@Test
@ -250,8 +247,7 @@ public class DomainApplicationDeleteFlowTest
createTld("tld", TldState.PREDELEGATION);
persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
}
@Test
@ -259,8 +255,7 @@ public class DomainApplicationDeleteFlowTest
createTld("tld", TldState.QUIET_PERIOD);
persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
}
@Test
@ -268,8 +263,7 @@ public class DomainApplicationDeleteFlowTest
createTld("tld", TldState.GENERAL_AVAILABILITY);
persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
}
@Test
@ -306,8 +300,7 @@ public class DomainApplicationDeleteFlowTest
public void testFailure_applicationIdForDifferentDomain() throws Exception {
persistResource(
newDomainApplication("invalid.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(ApplicationDomainNameMismatchException.class);
runFlow();
assertThrows(ApplicationDomainNameMismatchException.class, () -> runFlow());
}
@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.persistActiveHost;
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.collect.ImmutableList;
@ -261,9 +263,9 @@ public class DomainApplicationInfoFlowTest
@Test
public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -274,9 +276,9 @@ public class DomainApplicationInfoFlowTest
.setDeletionTime(clock.nowUtc().minusDays(1))
.setRegistrant(Key.create(persistActiveContact("jd1234")))
.build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -285,8 +287,7 @@ public class DomainApplicationInfoFlowTest
AppEngineRule.makeRegistrar1().asBuilder().setClientId("ClientZ").build());
sessionMetadata.setClientId("ClientZ");
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
@ -297,16 +298,14 @@ public class DomainApplicationInfoFlowTest
.setRegistrant(Key.create(persistActiveContact("jd1234")))
.setPhase(LaunchPhase.SUNRUSH)
.build());
thrown.expect(ApplicationDomainNameMismatchException.class);
runFlow();
assertThrows(ApplicationDomainNameMismatchException.class, () -> runFlow());
}
@Test
public void testFailure_noApplicationId() throws Exception {
setEppInput("domain_info_sunrise_no_application_id.xml");
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
thrown.expect(MissingApplicationIdException.class);
runFlow();
assertThrows(MissingApplicationIdException.class, () -> runFlow());
}
@Test
@ -314,8 +313,7 @@ public class DomainApplicationInfoFlowTest
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
application = persistResource(
application.asBuilder().setPhase(LaunchPhase.SUNRISE).build());
thrown.expect(ApplicationLaunchPhaseMismatchException.class);
runFlow();
assertThrows(ApplicationLaunchPhaseMismatchException.class, () -> runFlow());
}
/** 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.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableMap;
@ -371,8 +372,7 @@ public class DomainApplicationUpdateFlowTest
setEppInput("domain_update_sunrise_dsdata_add.xml");
persistResource(newApplicationBuilder().setDsData(builder.build()).build());
thrown.expect(TooManyDsRecordsException.class);
runFlow();
assertThrows(TooManyDsRecordsException.class, () -> runFlow());
}
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.
modifyApplicationToHave13Nameservers();
setEppInput("domain_update_sunrise_add_nameserver.xml");
thrown.expect(TooManyNameserversException.class);
runFlow();
assertThrows(TooManyNameserversException.class, () -> runFlow());
}
@Test
public void testFailure_wrongExtension() throws Exception {
setEppInput("domain_update_sunrise_wrong_extension.xml");
thrown.expect(UnimplementedExtensionException.class);
runFlow();
assertThrows(UnimplementedExtensionException.class, () -> runFlow());
}
@Test
public void testFailure_applicationDomainNameMismatch() throws Exception {
persistReferencedEntities();
persistResource(newApplicationBuilder().setFullyQualifiedDomainName("something.tld").build());
thrown.expect(ApplicationDomainNameMismatchException.class);
runFlow();
assertThrows(ApplicationDomainNameMismatchException.class, () -> runFlow());
}
@Test
public void testFailure_neverExisted() throws Exception {
persistReferencedEntities();
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistReferencedEntities();
persistResource(newApplicationBuilder().setDeletionTime(START_OF_TIME).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -437,8 +434,7 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities();
persistResource(newApplicationBuilder().setStatusValues(
ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)).build());
thrown.expect(ResourceHasClientUpdateProhibitedException.class);
runFlow();
assertThrows(ResourceHasClientUpdateProhibitedException.class, () -> runFlow());
}
@Test
@ -446,16 +442,15 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities();
persistResource(newApplicationBuilder().setStatusValues(
ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED)).build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("serverUpdateProhibited");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited");
}
private void doIllegalApplicationStatusTest(ApplicationStatus status) throws Exception {
persistReferencedEntities();
persistResource(newApplicationBuilder().setApplicationStatus(status).build());
thrown.expect(ApplicationStatusProhibitsUpdateException.class);
runFlow();
assertThrows(ApplicationStatusProhibitsUpdateException.class, () -> runFlow());
}
@Test
@ -479,9 +474,9 @@ public class DomainApplicationUpdateFlowTest
persistActiveContact("sh8013");
persistActiveContact("mak21");
persistNewApplication();
thrown.expect(LinkedResourcesDoNotExistException.class);
thrown.expectMessage("(ns2.example.tld)");
runFlow();
LinkedResourcesDoNotExistException thrown =
expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("(ns2.example.tld)");
}
@Test
@ -490,9 +485,9 @@ public class DomainApplicationUpdateFlowTest
persistActiveHost("ns2.example.tld");
persistActiveContact("mak21");
persistNewApplication();
thrown.expect(LinkedResourcesDoNotExistException.class);
thrown.expectMessage("(sh8013)");
runFlow();
LinkedResourcesDoNotExistException thrown =
expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("(sh8013)");
}
@Test
@ -505,8 +500,7 @@ public class DomainApplicationUpdateFlowTest
persistResource(reloadDomainApplication().asBuilder().setContacts(ImmutableSet.of(
DesignatedContact.create(Type.TECH, Key.create(
loadByForeignKey(ContactResource.class, "foo", clock.nowUtc()))))).build());
thrown.expect(DuplicateContactForRoleException.class);
runFlow();
assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
}
@Test
@ -514,8 +508,7 @@ public class DomainApplicationUpdateFlowTest
setEppInput("domain_update_sunrise_prohibited_status.xml");
persistReferencedEntities();
persistNewApplication();
thrown.expect(StatusNotClientSettableException.class);
runFlow();
assertThrows(StatusNotClientSettableException.class, () -> runFlow());
}
@ -536,8 +529,7 @@ public class DomainApplicationUpdateFlowTest
setEppInput("domain_update_sunrise_duplicate_contact.xml");
persistReferencedEntities();
persistNewApplication();
thrown.expect(DuplicateContactForRoleException.class);
runFlow();
assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
}
@Test
@ -546,8 +538,7 @@ public class DomainApplicationUpdateFlowTest
persistReferencedEntities();
persistNewApplication();
// We need to test for missing type, but not for invalid - the schema enforces that for us.
thrown.expect(MissingContactTypeException.class);
runFlow();
assertThrows(MissingContactTypeException.class, () -> runFlow());
}
@Test
@ -555,8 +546,7 @@ public class DomainApplicationUpdateFlowTest
sessionMetadata.setClientId("NewRegistrar");
persistReferencedEntities();
persistApplication();
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
@ -575,8 +565,7 @@ public class DomainApplicationUpdateFlowTest
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistReferencedEntities();
persistApplication();
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
}
@Test
@ -598,8 +587,7 @@ public class DomainApplicationUpdateFlowTest
.setNameservers(ImmutableSet.of(Key.create(
loadByForeignKey(HostResource.class, "ns1.example.tld", clock.nowUtc()))))
.build());
thrown.expect(AddRemoveSameValueException.class);
runFlow();
assertThrows(AddRemoveSameValueException.class, () -> runFlow());
}
@Test
@ -612,8 +600,7 @@ public class DomainApplicationUpdateFlowTest
Key.create(
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())))))
.build());
thrown.expect(AddRemoveSameValueException.class);
runFlow();
assertThrows(AddRemoveSameValueException.class, () -> runFlow());
}
@Test
@ -625,8 +612,7 @@ public class DomainApplicationUpdateFlowTest
DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact))))
.build());
thrown.expect(MissingAdminContactException.class);
runFlow();
assertThrows(MissingAdminContactException.class, () -> runFlow());
}
@Test
@ -638,8 +624,7 @@ public class DomainApplicationUpdateFlowTest
DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact))))
.build());
thrown.expect(MissingTechnicalContactException.class);
runFlow();
assertThrows(MissingTechnicalContactException.class, () -> runFlow());
}
@Test
@ -651,8 +636,7 @@ public class DomainApplicationUpdateFlowTest
.setAllowedRegistrantContactIds(ImmutableSet.of("contact1234"))
.build());
clock.advanceOneMilli();
thrown.expect(RegistrantNotAllowedException.class);
runFlow();
assertThrows(RegistrantNotAllowedException.class, () -> runFlow());
}
@Test
@ -664,8 +648,7 @@ public class DomainApplicationUpdateFlowTest
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
.build());
clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForTldException.class);
runFlow();
assertThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
}
@Test
@ -692,8 +675,8 @@ public class DomainApplicationUpdateFlowTest
ImmutableSet.of("ns1.example.tld", "ns2.example.tld"))
.build());
clock.advanceOneMilli();
thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class);
runFlow();
assertThrows(
NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, () -> runFlow());
}
@Test
@ -746,9 +729,9 @@ public class DomainApplicationUpdateFlowTest
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns3.example.tld"))
.build());
clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForDomainException.class);
thrown.expectMessage("ns2.example.tld");
runFlow();
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns2.example.tld");
}
@Test
@ -764,8 +747,8 @@ public class DomainApplicationUpdateFlowTest
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns2.example.tld"))
.build());
clock.advanceOneMilli();
thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class);
runFlow();
assertThrows(
NameserversNotSpecifiedForNameserverRestrictedDomainException.class, () -> runFlow());
}
@Test
@ -825,9 +808,9 @@ public class DomainApplicationUpdateFlowTest
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns3.example.tld"))
.build());
clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForDomainException.class);
thrown.expectMessage("ns2.example.tld");
runFlow();
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns2.example.tld");
}
@Test
@ -845,9 +828,9 @@ public class DomainApplicationUpdateFlowTest
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.tld:ns2.example.tld"))
.build());
clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForTldException.class);
thrown.expectMessage("ns2.example.tld");
runFlow();
NameserversNotAllowedForTldException thrown =
expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns2.example.tld");
}
@Test
@ -859,8 +842,7 @@ public class DomainApplicationUpdateFlowTest
"domain_update_sunrise_fee.xml",
ImmutableMap.of("DOMAIN", "non-free-update.tld", "AMOUNT", "12.00"));
clock.advanceOneMilli();
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test

View file

@ -274,23 +274,20 @@ public class DomainCheckFlowTest
@Test
public void testFailure_tooManyIds() throws Exception {
setEppInput("domain_check_51.xml");
thrown.expect(TooManyResourceChecksException.class);
runFlow();
assertThrows(TooManyResourceChecksException.class, () -> runFlow());
}
@Test
public void testFailure_wrongTld() throws Exception {
setEppInput("domain_check.xml");
thrown.expect(TldDoesNotExistException.class);
runFlow();
assertThrows(TldDoesNotExistException.class, () -> runFlow());
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
}
@Test
@ -389,8 +386,7 @@ public class DomainCheckFlowTest
@Test
public void testFailure_predelegation() throws Exception {
createTld("tld", TldState.PREDELEGATION);
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
}
@Test
@ -677,177 +673,152 @@ public class DomainCheckFlowTest
@Test
public void testFeeExtension_wrongCurrency_v06() throws Exception {
setEppInput("domain_check_fee_euro_v06.xml");
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
public void testFeeExtension_wrongCurrency_v11() throws Exception {
setEppInput("domain_check_fee_euro_v11.xml");
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
public void testFeeExtension_wrongCurrency_v12() throws Exception {
setEppInput("domain_check_fee_euro_v12.xml");
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
public void testFeeExtension_periodNotInYears_v06() throws Exception {
setEppInput("domain_check_fee_bad_period_v06.xml");
thrown.expect(BadPeriodUnitException.class);
runFlow();
assertThrows(BadPeriodUnitException.class, () -> runFlow());
}
@Test
public void testFeeExtension_periodNotInYears_v11() throws Exception {
setEppInput("domain_check_fee_bad_period_v11.xml");
thrown.expect(BadPeriodUnitException.class);
runFlow();
assertThrows(BadPeriodUnitException.class, () -> runFlow());
}
@Test
public void testFeeExtension_periodNotInYears_v12() throws Exception {
setEppInput("domain_check_fee_bad_period_v12.xml");
thrown.expect(BadPeriodUnitException.class);
runFlow();
assertThrows(BadPeriodUnitException.class, () -> runFlow());
}
@Test
public void testFeeExtension_commandWithPhase_v06() throws Exception {
setEppInput("domain_check_fee_command_phase_v06.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
}
@Test
public void testFeeExtension_commandWithPhase_v11() throws Exception {
setEppInput("domain_check_fee_command_phase_v11.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
}
@Test
public void testFeeExtension_commandWithPhase_v12() throws Exception {
setEppInput("domain_check_fee_command_phase_v12.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
}
@Test
public void testFeeExtension_commandSubphase_v06() throws Exception {
setEppInput("domain_check_fee_command_subphase_v06.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
}
@Test
public void testFeeExtension_commandSubphase_v11() throws Exception {
setEppInput("domain_check_fee_command_subphase_v11.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
}
@Test
public void testFeeExtension_commandSubphase_v12() throws Exception {
setEppInput("domain_check_fee_command_subphase_v12.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
}
// This test is only relevant for v06, since domain names are not specified in v11 or v12.
@Test
public void testFeeExtension_feeCheckNotInAvailabilityCheck() throws Exception {
setEppInput("domain_check_fee_not_in_avail.xml");
thrown.expect(OnlyCheckedNamesCanBeFeeCheckedException.class);
runFlow();
assertThrows(OnlyCheckedNamesCanBeFeeCheckedException.class, () -> runFlow());
}
@Test
public void testFeeExtension_multiyearRestore_v06() throws Exception {
setEppInput("domain_check_fee_multiyear_restore_v06.xml");
thrown.expect(RestoresAreAlwaysForOneYearException.class);
runFlow();
assertThrows(RestoresAreAlwaysForOneYearException.class, () -> runFlow());
}
@Test
public void testFeeExtension_multiyearRestore_v11() throws Exception {
setEppInput("domain_check_fee_multiyear_restore_v11.xml");
thrown.expect(RestoresAreAlwaysForOneYearException.class);
runFlow();
assertThrows(RestoresAreAlwaysForOneYearException.class, () -> runFlow());
}
@Test
public void testFeeExtension_multiyearRestore_v12() throws Exception {
setEppInput("domain_check_fee_multiyear_restore_v12.xml");
thrown.expect(RestoresAreAlwaysForOneYearException.class);
runFlow();
assertThrows(RestoresAreAlwaysForOneYearException.class, () -> runFlow());
}
@Test
public void testFeeExtension_multiyearTransfer_v06() throws Exception {
setEppInput("domain_check_fee_multiyear_transfer_v06.xml");
thrown.expect(TransfersAreAlwaysForOneYearException.class);
runFlow();
assertThrows(TransfersAreAlwaysForOneYearException.class, () -> runFlow());
}
@Test
public void testFeeExtension_multiyearTransfer_v11() throws Exception {
setEppInput("domain_check_fee_multiyear_transfer_v11.xml");
thrown.expect(TransfersAreAlwaysForOneYearException.class);
runFlow();
assertThrows(TransfersAreAlwaysForOneYearException.class, () -> runFlow());
}
@Test
public void testFeeExtension_multiyearTransfer_v12() throws Exception {
setEppInput("domain_check_fee_multiyear_transfer_v12.xml");
thrown.expect(TransfersAreAlwaysForOneYearException.class);
runFlow();
assertThrows(TransfersAreAlwaysForOneYearException.class, () -> runFlow());
}
@Test
public void testFeeExtension_unknownCommand_v06() throws Exception {
setEppInput("domain_check_fee_unknown_command_v06.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
assertThrows(UnknownFeeCommandException.class, () -> runFlow());
}
@Test
public void testFeeExtension_unknownCommand_v11() throws Exception {
setEppInput("domain_check_fee_unknown_command_v11.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
assertThrows(UnknownFeeCommandException.class, () -> runFlow());
}
@Test
public void testFeeExtension_unknownCommand_v12() throws Exception {
setEppInput("domain_check_fee_unknown_command_v12.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
assertThrows(UnknownFeeCommandException.class, () -> runFlow());
}
@Test
public void testFeeExtension_invalidCommand_v06() throws Exception {
setEppInput("domain_check_fee_invalid_command_v06.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
assertThrows(UnknownFeeCommandException.class, () -> runFlow());
}
@Test
public void testFeeExtension_invalidCommand_v11() throws Exception {
setEppInput("domain_check_fee_invalid_command_v11.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
assertThrows(UnknownFeeCommandException.class, () -> runFlow());
}
@Test
public void testFeeExtension_invalidCommand_v12() throws Exception {
setEppInput("domain_check_fee_invalid_command_v12.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
assertThrows(UnknownFeeCommandException.class, () -> runFlow());
}
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.loadRegistrar;
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.ImmutableSet;
@ -101,23 +102,20 @@ public class DomainClaimsCheckFlowTest
@Test
public void testFailure_TooManyIds() throws Exception {
setEppInput("domain_check_claims_51.xml");
thrown.expect(TooManyResourceChecksException.class);
runFlow();
assertThrows(TooManyResourceChecksException.class, () -> runFlow());
}
@Test
public void testFailure_tldDoesntExist() throws Exception {
setEppInput("domain_check_claims_bad_tld.xml");
thrown.expect(TldDoesNotExistException.class);
runFlow();
assertThrows(TldDoesNotExistException.class, () -> runFlow());
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
}
@Test
@ -138,8 +136,7 @@ public class DomainClaimsCheckFlowTest
createTld("tld", TldState.PREDELEGATION);
persistResource(Registry.get("tld").asBuilder().build());
setEppInput("domain_check_claims.xml");
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
}
@Test
@ -147,8 +144,7 @@ public class DomainClaimsCheckFlowTest
createTld("tld", TldState.SUNRISE);
persistResource(Registry.get("tld").asBuilder().build());
setEppInput("domain_check_claims.xml");
thrown.expect(DomainClaimsCheckNotAllowedInSunrise.class);
runFlow();
assertThrows(DomainClaimsCheckNotAllowedInSunrise.class, () -> runFlow());
}
@Test
@ -158,8 +154,7 @@ public class DomainClaimsCheckFlowTest
persistResource(
Registry.get("tld2").asBuilder().setClaimsPeriodEnd(clock.nowUtc().minusMillis(1)).build());
setEppInput("domain_check_claims_multiple_tlds.xml");
thrown.expect(ClaimsPeriodEndedException.class);
runFlow();
assertThrows(ClaimsPeriodEndedException.class, () -> runFlow());
}
@Test

View file

@ -386,8 +386,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTlds("foo.tld", "tld");
setEppInput("domain_create_wildcard.xml", ImmutableMap.of("DOMAIN", "foo.tld"));
persistContactsAndHosts();
thrown.expect(DomainNameExistsAsTldException.class);
runFlow();
assertThrows(DomainNameExistsAsTldException.class, () -> runFlow());
}
@Test
@ -395,8 +394,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTlds("foo.tld", "tld");
setEppInput("domain_create_wildcard.xml", ImmutableMap.of("DOMAIN", "FOO.TLD"));
persistContactsAndHosts();
thrown.expect(BadDomainNameCharacterException.class);
runFlow();
assertThrows(BadDomainNameCharacterException.class, () -> runFlow());
}
@Test
@ -536,72 +534,63 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_refundableFee_v06() throws Exception {
setEppInput("domain_create_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_refundableFee_v11() throws Exception {
setEppInput("domain_create_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_refundableFee_v12() throws Exception {
setEppInput("domain_create_fee_refundable.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_gracePeriodFee_v06() throws Exception {
setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_gracePeriodFee_v11() throws Exception {
setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_gracePeriodFee_v12() throws Exception {
setEppInput("domain_create_fee_grace_period.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_appliedFee_v06() throws Exception {
setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_appliedFee_v11() throws Exception {
setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_appliedFee_v12() throws Exception {
setEppInput("domain_create_fee_applied.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -621,8 +610,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_metadataNotFromTool() throws Exception {
setEppInput("domain_create_metadata.xml");
persistContactsAndHosts();
thrown.expect(OnlyToolCanPassMetadataException.class);
runFlow();
assertThrows(OnlyToolCanPassMetadataException.class, () -> runFlow());
}
@Test
@ -649,9 +637,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setLrpPeriod(new Interval(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1)))
.build());
persistContactsAndHosts();
thrown.expect(InvalidLrpTokenException.class);
thrown.expectMessage("Invalid limited registration period token");
runFlow();
InvalidLrpTokenException thrown = expectThrows(InvalidLrpTokenException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("Invalid limited registration period token");
}
@Test
@ -750,8 +737,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_periodInMonths() throws Exception {
setEppInput("domain_create_months.xml");
persistContactsAndHosts();
thrown.expect(BadPeriodUnitException.class);
runFlow();
assertThrows(BadPeriodUnitException.class, () -> runFlow());
}
@Test
@ -783,8 +769,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistClaimsList(ImmutableMap.of("example", CLAIMS_KEY));
setEppInput("domain_create.xml");
persistContactsAndHosts();
thrown.expect(MissingClaimsNoticeException.class);
runFlow();
assertThrows(MissingClaimsNoticeException.class, () -> runFlow());
}
@Test
@ -792,8 +777,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
setEppInput("domain_create_claim_notice.xml");
persistClaimsList(ImmutableMap.of());
persistContactsAndHosts();
thrown.expect(UnexpectedClaimsNoticeException.class);
runFlow();
assertThrows(UnexpectedClaimsNoticeException.class, () -> runFlow());
}
@Test
@ -804,40 +788,35 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource(Registry.get("tld").asBuilder()
.setClaimsPeriodEnd(clock.nowUtc())
.build());
thrown.expect(ClaimsPeriodEndedException.class);
runFlow();
assertThrows(ClaimsPeriodEndedException.class, () -> runFlow());
}
@Test
public void testFailure_tooManyNameservers() throws Exception {
setEppInput("domain_create_14_nameservers.xml");
persistContactsAndHosts();
thrown.expect(TooManyNameserversException.class);
runFlow();
assertThrows(TooManyNameserversException.class, () -> runFlow());
}
@Test
public void testFailure_secDnsMaxSigLife() throws Exception {
setEppInput("domain_create_dsdata.xml");
persistContactsAndHosts();
thrown.expect(MaxSigLifeNotSupportedException.class);
runFlow();
assertThrows(MaxSigLifeNotSupportedException.class, () -> runFlow());
}
@Test
public void testFailure_secDnsTooManyDsRecords() throws Exception {
setEppInput("domain_create_dsdata_9_records.xml");
persistContactsAndHosts();
thrown.expect(TooManyDsRecordsException.class);
runFlow();
assertThrows(TooManyDsRecordsException.class, () -> runFlow());
}
@Test
public void testFailure_wrongExtension() throws Exception {
setEppInput("domain_create_wrong_extension.xml");
persistContactsAndHosts();
thrown.expect(UnimplementedExtensionException.class);
runFlow();
assertThrows(UnimplementedExtensionException.class, () -> runFlow());
}
@Test
@ -846,8 +825,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource(
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts();
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test
@ -856,8 +834,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource(
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts();
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test
@ -866,8 +843,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource(
Registry.get("tld").asBuilder().setCreateBillingCost(Money.of(USD, 20)).build());
persistContactsAndHosts();
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test
@ -882,8 +858,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistContactsAndHosts();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
@ -898,8 +873,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistContactsAndHosts();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
@ -914,8 +888,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistContactsAndHosts();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
@ -939,16 +912,14 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_reserved() throws Exception {
setEppInput("domain_create_reserved.xml");
persistContactsAndHosts();
thrown.expect(DomainReservedException.class);
runFlow();
assertThrows(DomainReservedException.class, () -> runFlow());
}
@Test
public void testFailure_anchorTenantViaAuthCode_wrongAuthCode() throws Exception {
setEppInput("domain_create_anchor_wrong_authcode.xml");
persistContactsAndHosts();
thrown.expect(DomainReservedException.class);
runFlow();
assertThrows(DomainReservedException.class, () -> runFlow());
}
@Test
@ -1045,9 +1016,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistActiveHost("ns1.example.net");
persistActiveContact("jd1234");
persistActiveContact("sh8013");
thrown.expect(LinkedResourcesDoNotExistException.class);
thrown.expectMessage("(ns2.example.net)");
runFlow();
LinkedResourcesDoNotExistException thrown =
expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("(ns2.example.net)");
}
@Test
@ -1059,9 +1030,10 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
clock.advanceOneMilli();
thrown.expect(LinkedResourceInPendingDeleteProhibitsOperationException.class);
thrown.expectMessage("ns2.example.net");
runFlow();
LinkedResourceInPendingDeleteProhibitsOperationException thrown =
expectThrows(
LinkedResourceInPendingDeleteProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns2.example.net");
}
@Test
@ -1069,8 +1041,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistContactsAndHosts();
persistActiveDomainApplication(getUniqueIdFromCommand());
clock.advanceOneMilli();
thrown.expect(DomainHasOpenApplicationsException.class);
runFlow();
assertThrows(DomainHasOpenApplicationsException.class, () -> runFlow());
}
@Test
@ -1095,9 +1066,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistActiveHost("ns1.example.net");
persistActiveHost("ns2.example.net");
persistActiveContact("jd1234");
thrown.expect(LinkedResourcesDoNotExistException.class);
thrown.expectMessage("(sh8013)");
runFlow();
LinkedResourcesDoNotExistException thrown =
expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("(sh8013)");
}
@Test
@ -1109,57 +1080,52 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
clock.advanceOneMilli();
thrown.expect(LinkedResourceInPendingDeleteProhibitsOperationException.class);
thrown.expectMessage("jd1234");
runFlow();
LinkedResourceInPendingDeleteProhibitsOperationException thrown =
expectThrows(
LinkedResourceInPendingDeleteProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("jd1234");
}
@Test
public void testFailure_wrongTld() throws Exception {
persistContactsAndHosts("net");
deleteTld("tld");
thrown.expect(TldDoesNotExistException.class);
runFlow();
assertThrows(TldDoesNotExistException.class, () -> runFlow());
}
@Test
public void testFailure_predelegation() throws Exception {
createTld("tld", TldState.PREDELEGATION);
persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
runFlow();
assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
}
@Test
public void testFailure_sunrise() throws Exception {
createTld("tld", TldState.SUNRISE);
persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
runFlow();
assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
}
@Test
public void testFailure_sunrush() throws Exception {
createTld("tld", TldState.SUNRUSH);
persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
runFlow();
assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
}
@Test
public void testFailure_landrush() throws Exception {
createTld("tld", TldState.LANDRUSH);
persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
runFlow();
assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
}
@Test
public void testFailure_quietPeriod() throws Exception {
createTld("tld", TldState.QUIET_PERIOD);
persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
runFlow();
assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
}
@Test
@ -1232,8 +1198,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_duplicateContact() throws Exception {
setEppInput("domain_create_duplicate_contact.xml");
persistContactsAndHosts();
thrown.expect(DuplicateContactForRoleException.class);
runFlow();
assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
}
@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.
setEppInput("domain_create_missing_contact_type.xml");
persistContactsAndHosts();
thrown.expect(MissingContactTypeException.class);
runFlow();
assertThrows(MissingContactTypeException.class, () -> runFlow());
}
@Test
public void testFailure_missingRegistrant() throws Exception {
setEppInput("domain_create_missing_registrant.xml");
persistContactsAndHosts();
thrown.expect(MissingRegistrantException.class);
runFlow();
assertThrows(MissingRegistrantException.class, () -> runFlow());
}
@Test
public void testFailure_missingAdmin() throws Exception {
setEppInput("domain_create_missing_admin.xml");
persistContactsAndHosts();
thrown.expect(MissingAdminContactException.class);
runFlow();
assertThrows(MissingAdminContactException.class, () -> runFlow());
}
@Test
public void testFailure_missingTech() throws Exception {
setEppInput("domain_create_missing_tech.xml");
persistContactsAndHosts();
thrown.expect(MissingTechnicalContactException.class);
runFlow();
assertThrows(MissingTechnicalContactException.class, () -> runFlow());
}
@Test
public void testFailure_missingNonRegistrantContacts() throws Exception {
setEppInput("domain_create_missing_non_registrant_contacts.xml");
persistContactsAndHosts();
thrown.expect(MissingAdminContactException.class);
runFlow();
assertThrows(MissingAdminContactException.class, () -> runFlow());
}
@Test
@ -1282,8 +1242,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("xn--q9jyb4c");
setEppInput("domain_create_bad_idn_minna.xml");
persistContactsAndHosts("net");
thrown.expect(InvalidIdnDomainLabelException.class);
runFlow();
assertThrows(InvalidIdnDomainLabelException.class, () -> runFlow());
}
@Test
@ -1291,16 +1250,14 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
setEppInput("domain_create_bad_validator_id.xml");
persistClaimsList(ImmutableMap.of("exampleone", CLAIMS_KEY));
persistContactsAndHosts();
thrown.expect(InvalidTrademarkValidatorException.class);
runFlow();
assertThrows(InvalidTrademarkValidatorException.class, () -> runFlow());
}
@Test
public void testFailure_codeMark() throws Exception {
setEppInput("domain_create_code_with_mark.xml");
persistContactsAndHosts();
thrown.expect(UnsupportedMarkTypeException.class);
runFlow();
assertThrows(UnsupportedMarkTypeException.class, () -> runFlow());
}
@Test
@ -1308,8 +1265,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("tld", TldState.SUNRISE);
setEppInput("domain_create_signed_mark.xml");
persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
runFlow();
assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
}
@Test
@ -1317,8 +1273,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
clock.setTo(DateTime.parse("2010-08-17T09:00:00.0Z"));
setEppInput("domain_create_claim_notice.xml");
persistContactsAndHosts();
thrown.expect(ExpiredClaimException.class);
runFlow();
assertThrows(ExpiredClaimException.class, () -> runFlow());
}
@Test
@ -1326,8 +1281,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
clock.setTo(DateTime.parse("2009-09-16T09:00:00.0Z"));
setEppInput("domain_create_claim_notice.xml");
persistContactsAndHosts();
thrown.expect(AcceptedTooLongAgoException.class);
runFlow();
assertThrows(AcceptedTooLongAgoException.class, () -> runFlow());
}
@Test
@ -1335,8 +1289,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z"));
setEppInput("domain_create_malformed_claim_notice1.xml");
persistContactsAndHosts();
thrown.expect(MalformedTcnIdException.class);
runFlow();
assertThrows(MalformedTcnIdException.class, () -> runFlow());
}
@Test
@ -1344,8 +1297,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z"));
setEppInput("domain_create_malformed_claim_notice2.xml");
persistContactsAndHosts();
thrown.expect(MalformedTcnIdException.class);
runFlow();
assertThrows(MalformedTcnIdException.class, () -> runFlow());
}
@Test
@ -1353,8 +1305,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
clock.setTo(DateTime.parse("2009-08-16T09:00:00.0Z"));
setEppInput("domain_create_bad_checksum_claim_notice.xml");
persistContactsAndHosts();
thrown.expect(InvalidTcnIdChecksumException.class);
runFlow();
assertThrows(InvalidTcnIdChecksumException.class, () -> runFlow());
}
@Test
@ -1367,8 +1318,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource(loadRegistrar("TheRegistrar").asBuilder()
.setBlockPremiumNames(true)
.build());
thrown.expect(PremiumNameBlockedException.class);
runFlow();
assertThrows(PremiumNameBlockedException.class, () -> runFlow());
}
@Test
@ -1376,8 +1326,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("example");
setEppInput("domain_create_premium.xml");
persistContactsAndHosts("net");
thrown.expect(FeesRequiredForPremiumNameException.class);
runFlow();
assertThrows(FeesRequiredForPremiumNameException.class, () -> runFlow());
}
@Test
@ -1388,8 +1337,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("net");
setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts();
thrown.expect(UndeclaredServiceExtensionException.class);
runFlow();
assertThrows(UndeclaredServiceExtensionException.class, () -> runFlow());
}
@Test
@ -1400,8 +1348,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("net");
setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts();
thrown.expect(UndeclaredServiceExtensionException.class);
runFlow();
assertThrows(UndeclaredServiceExtensionException.class, () -> runFlow());
}
@Test
@ -1412,32 +1359,28 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("net");
setEppInput("domain_create_fee.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts();
thrown.expect(UndeclaredServiceExtensionException.class);
runFlow();
assertThrows(UndeclaredServiceExtensionException.class, () -> runFlow());
}
@Test
public void testFailure_feeGivenInWrongScale_v06() throws Exception {
setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
persistContactsAndHosts();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception {
setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistContactsAndHosts();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception {
setEppInput("domain_create_fee_bad_scale.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
persistContactsAndHosts();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@Test
@ -1450,8 +1393,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.asBuilder()
.setState(State.SUSPENDED)
.build());
thrown.expect(RegistrarMustBeActiveToCreateDomainsException.class);
runFlow();
assertThrows(RegistrarMustBeActiveToCreateDomainsException.class, () -> runFlow());
}
private void doFailingDomainNameTest(
@ -1534,8 +1476,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("tld", TldState.SUNRISE);
setEppInput("domain_create_registration_sunrise.xml");
persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
runFlow();
assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
}
@Test
@ -1586,8 +1527,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("tld", TldState.SUNRUSH);
setEppInput("domain_create_registration_sunrush.xml");
persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
runFlow();
assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
}
@Test
@ -1599,8 +1539,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setAllowedTlds(ImmutableSet.of("irrelevant"))
.build());
persistContactsAndHosts();
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
}
@Test
@ -1651,8 +1590,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
createTld("tld", TldState.LANDRUSH);
setEppInput("domain_create_registration_landrush.xml");
persistContactsAndHosts();
thrown.expect(NoGeneralRegistrationsInCurrentPhaseException.class);
runFlow();
assertThrows(NoGeneralRegistrationsInCurrentPhaseException.class, () -> runFlow());
}
@Test
@ -1705,9 +1643,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource(Registry.get("tld").asBuilder()
.setAllowedRegistrantContactIds(ImmutableSet.of("someone"))
.build());
thrown.expect(RegistrantNotAllowedException.class);
thrown.expectMessage("jd1234");
runFlow();
RegistrantNotAllowedException thrown =
expectThrows(RegistrantNotAllowedException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("jd1234");
}
@Test
@ -1716,9 +1654,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistResource(Registry.get("tld").asBuilder()
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns2.example.net"))
.build());
thrown.expect(NameserversNotAllowedForTldException.class);
thrown.expectMessage("ns1.example.net");
runFlow();
NameserversNotAllowedForTldException thrown =
expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -1728,8 +1666,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("somethingelse.example.net"))
.build());
persistContactsAndHosts();
thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class);
runFlow();
assertThrows(
NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, () -> runFlow());
}
@Test
@ -1770,8 +1708,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
"example,NAMESERVER_RESTRICTED,"
+ "ns1.example.net:ns2.example.net:ns3.example.net"))
.build());
thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class);
runFlow();
assertThrows(
NameserversNotSpecifiedForNameserverRestrictedDomainException.class, () -> runFlow());
}
@Test
@ -1784,9 +1722,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistReservedList(
"reserved", "example,NAMESERVER_RESTRICTED,ns2.example.net:ns3.example.net"))
.build());
thrown.expect(NameserversNotAllowedForDomainException.class);
thrown.expectMessage("ns1.example.net");
runFlow();
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -1800,9 +1738,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
persistReservedList(
"reserved", "lol,NAMESERVER_RESTRICTED,ns1.example.net:ns2.example.net"))
.build());
thrown.expect(DomainNotAllowedForTldWithCreateRestrictionException.class);
thrown.expectMessage("example.tld");
runFlow();
DomainNotAllowedForTldWithCreateRestrictionException thrown =
expectThrows(DomainNotAllowedForTldWithCreateRestrictionException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("example.tld");
}
@Test
@ -1850,9 +1788,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
"example,NAMESERVER_RESTRICTED,"
+ "ns1.example.net:ns2.example.net:ns3.example.net"))
.build());
thrown.expect(NameserversNotAllowedForTldException.class);
thrown.expectMessage("ns1.example.net");
runFlow();
NameserversNotAllowedForTldException thrown =
expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -1869,9 +1807,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
"example,NAMESERVER_RESTRICTED,"
+ "ns2.example.net:ns3.example.net:ns4.example.net"))
.build());
thrown.expect(NameserversNotAllowedForDomainException.class);
thrown.expectMessage("ns1.example.net");
runFlow();
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns1.example.net");
}
@Test
@ -1890,9 +1828,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
"lol,NAMESERVER_RESTRICTED,"
+ "ns1.example.net:ns2.example.net:ns3.example.net"))
.build());
thrown.expect(DomainNotAllowedForTldWithCreateRestrictionException.class);
thrown.expectMessage("example.tld");
runFlow();
DomainNotAllowedForTldWithCreateRestrictionException thrown =
expectThrows(DomainNotAllowedForTldWithCreateRestrictionException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("example.tld");
}
@Test
@ -2020,8 +1958,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testFailure_max10Years() throws Exception {
setEppInput("domain_create_11_years.xml");
persistContactsAndHosts();
thrown.expect(ExceedsMaxRegistrationYearsException.class);
runFlow();
assertThrows(ExceedsMaxRegistrationYearsException.class, () -> runFlow());
}
@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.DomainResourceSubject.assertAboutDomains;
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.util.DateTimeUtils.END_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 {
createTld("tld", TldState.PREDELEGATION);
setUpSuccessfulTest();
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
assertThrows(BadCommandForRegistryPhaseException.class, () -> runFlow());
}
@Test
@ -651,17 +652,17 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
@Test
public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -674,16 +675,14 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
domain = persistResource(domain.asBuilder()
.addSubordinateHost(subordinateHost.getFullyQualifiedHostName())
.build());
thrown.expect(DomainToDeleteHasHostsException.class);
runFlow();
assertThrows(DomainToDeleteHasHostsException.class, () -> runFlow());
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
@ -700,8 +699,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
setUpSuccessfulTest();
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
}
@Test
@ -719,9 +717,9 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.addStatusValue(StatusValue.CLIENT_DELETE_PROHIBITED)
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("clientDeleteProhibited");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("clientDeleteProhibited");
}
@Test
@ -729,9 +727,9 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.addStatusValue(StatusValue.SERVER_DELETE_PROHIBITED)
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("serverDeleteProhibited");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("serverDeleteProhibited");
}
@Test
@ -739,9 +737,9 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("pendingDelete");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("pendingDelete");
}
@Test
@ -764,8 +762,7 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
public void testFailure_metadataNotFromTool() throws Exception {
setEppInput("domain_delete_metadata.xml");
persistResource(newDomainResource(getUniqueIdFromCommand()));
thrown.expect(OnlyToolCanPassMetadataException.class);
runFlow();
assertThrows(OnlyToolCanPassMetadataException.class, () -> runFlow());
}
@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.persistActiveHost;
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.collect.ImmutableMap;
@ -373,9 +375,9 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
@Test
public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -383,9 +385,9 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
persistResource(newDomainResource("example.tld").asBuilder()
.setDeletionTime(clock.nowUtc().minusDays(1))
.build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -397,8 +399,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
.build());
sessionMetadata.setClientId("ClientZ");
setEppInput("domain_info_with_auth.xml");
thrown.expect(BadAuthInfoForResourceException.class);
runFlow();
assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
}
@Test
@ -409,8 +410,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("diffpw")))
.build());
setEppInput("domain_info_with_auth.xml");
thrown.expect(BadAuthInfoForResourceException.class);
runFlow();
assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
}
@Test
@ -425,8 +425,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our registrant.
eppLoader.replaceAll("JD1234-REP", registrant.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class);
runFlow();
assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
}
@Test
@ -440,8 +439,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our registrant.
eppLoader.replaceAll("JD1234-REP", registrant.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class);
runFlow();
assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
}
@Test
@ -456,8 +454,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our contact.
eppLoader.replaceAll("JD1234-REP", contact.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class);
runFlow();
assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
}
@Test
@ -471,8 +468,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our contact.
eppLoader.replaceAll("JD1234-REP", contact.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class);
runFlow();
assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
}
@Test
@ -483,8 +479,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our unrelated contact.
eppLoader.replaceAll("JD1234-REP", unrelatedContact.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class);
runFlow();
assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
}
@Test
@ -494,8 +489,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
setEppInput("domain_info_with_contact_auth.xml");
// Replace the ROID in the xml file with the one for our unrelated contact.
eppLoader.replaceAll("JD1234-REP", unrelatedContact.getRepoId());
thrown.expect(BadAuthInfoForResourceException.class);
runFlow();
assertThrows(BadAuthInfoForResourceException.class, () -> runFlow());
}
/**
@ -574,8 +568,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
public void testFeeExtension_wrongCurrency() throws Exception {
setEppInput("domain_info_fee_create_euro.xml");
persistTestEntities(false);
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
/** 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 {
setEppInput("domain_info_fee_bad_period.xml");
persistTestEntities(false);
thrown.expect(BadPeriodUnitException.class);
runFlow();
assertThrows(BadPeriodUnitException.class, () -> runFlow());
}
/** Test a command that specifies a phase. */
@ -592,8 +584,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
public void testFeeExtension_commandPhase() throws Exception {
setEppInput("domain_info_fee_command_phase.xml");
persistTestEntities(false);
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
}
/** Test a command that specifies a subphase. */
@ -601,8 +592,7 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
public void testFeeExtension_commandSubphase() throws Exception {
setEppInput("domain_info_fee_command_subphase.xml");
persistTestEntities(false);
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
assertThrows(FeeChecksDontSupportPhasesException.class, () -> runFlow());
}
/** 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 {
setEppInput("domain_info_fee_multiyear_restore.xml");
persistTestEntities(false);
thrown.expect(RestoresAreAlwaysForOneYearException.class);
runFlow();
assertThrows(RestoresAreAlwaysForOneYearException.class, () -> runFlow());
}
/** 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 {
setEppInput("domain_info_fee_multiyear_transfer.xml");
persistTestEntities(false);
thrown.expect(TransfersAreAlwaysForOneYearException.class);
runFlow();
assertThrows(TransfersAreAlwaysForOneYearException.class, () -> runFlow());
}
/** 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.DomainResourceSubject.assertAboutDomains;
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.START_OF_TIME;
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 {
setEppInput("domain_renew_fee_refundable.xml", FEE_06_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_refundableFee_v11() throws Exception {
setEppInput("domain_renew_fee_refundable.xml", FEE_11_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_refundableFee_v12() throws Exception {
setEppInput("domain_renew_fee_refundable.xml", FEE_12_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_gracePeriodFee_v06() throws Exception {
setEppInput("domain_renew_fee_grace_period.xml", FEE_06_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_gracePeriodFee_v11() throws Exception {
setEppInput("domain_renew_fee_grace_period.xml", FEE_11_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_gracePeriodFee_v12() throws Exception {
setEppInput("domain_renew_fee_grace_period.xml", FEE_12_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_appliedFee_v06() throws Exception {
setEppInput("domain_renew_fee_applied.xml", FEE_06_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_appliedFee_v11() throws Exception {
setEppInput("domain_renew_fee_applied.xml", FEE_11_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_appliedFee_v12() throws Exception {
setEppInput("domain_renew_fee_applied.xml", FEE_12_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -410,33 +403,33 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
@Test
public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_clientRenewProhibited() throws Exception {
persistDomain(StatusValue.CLIENT_RENEW_PROHIBITED);
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("clientRenewProhibited");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("clientRenewProhibited");
}
@Test
public void testFailure_serverRenewProhibited() throws Exception {
persistDomain(StatusValue.SERVER_RENEW_PROHIBITED);
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("serverRenewProhibited");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("serverRenewProhibited");
}
@Test
@ -446,9 +439,9 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setDeletionTime(clock.nowUtc().plusDays(1))
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("pendingDelete");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("pendingDelete");
}
@Test
@ -460,8 +453,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build());
persistDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test
@ -473,8 +465,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build());
persistDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test
@ -486,8 +477,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build());
persistDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test
@ -504,8 +494,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
@ -522,8 +511,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
@ -540,32 +528,28 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
public void testFailure_feeGivenInWrongScale_v06() throws Exception {
setEppInput("domain_renew_fee_bad_scale.xml", FEE_06_MAP);
persistDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception {
setEppInput("domain_renew_fee_bad_scale.xml", FEE_11_MAP);
persistDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception {
setEppInput("domain_renew_fee_bad_scale.xml", FEE_12_MAP);
persistDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@Test
@ -575,25 +559,23 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.asBuilder()
.setRegistrationExpirationTime(DateTime.parse("2001-09-08T22:00:00.0Z"))
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("pendingTransfer");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("pendingTransfer");
}
@Test
public void testFailure_periodInMonths() throws Exception {
setEppInput("domain_renew_months.xml");
persistDomain();
thrown.expect(BadPeriodUnitException.class);
runFlow();
assertThrows(BadPeriodUnitException.class, () -> runFlow());
}
@Test
public void testFailure_max10Years() throws Exception {
setEppInput("domain_renew_11_years.xml");
persistDomain();
thrown.expect(ExceedsMaxRegistrationYearsException.class);
runFlow();
assertThrows(ExceedsMaxRegistrationYearsException.class, () -> runFlow());
}
@Test
@ -603,16 +585,14 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
persistResource(reloadResourceByForeignKey().asBuilder()
.setRegistrationExpirationTime(DateTime.parse("2000-04-04T22:00:00.0Z"))
.build());
thrown.expect(IncorrectCurrentExpirationDateException.class);
runFlow();
assertThrows(IncorrectCurrentExpirationDateException.class, () -> runFlow());
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
@ -628,8 +608,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistDomain();
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
}
@Test
@ -647,8 +626,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
persistResource(Registry.get("example").asBuilder().setPremiumPriceAckRequired(true).build());
setEppInput("domain_renew_premium.xml");
persistDomain();
thrown.expect(FeesRequiredForPremiumNameException.class);
runFlow();
assertThrows(FeesRequiredForPremiumNameException.class, () -> runFlow());
}
@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.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -232,72 +234,63 @@ public class DomainRestoreRequestFlowTest extends
public void testFailure_refundableFee_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_06_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_refundableFee_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_11_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_refundableFee_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_12_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_gracePeriodFee_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_06_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_gracePeriodFee_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_11_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_gracePeriodFee_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_12_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_appliedFee_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_06_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_appliedFee_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_11_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
public void testFailure_appliedFee_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_12_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
assertThrows(UnsupportedFeeAttributeException.class, () -> runFlow());
}
@Test
@ -340,9 +333,9 @@ public class DomainRestoreRequestFlowTest extends
@Test
public void testFailure_doesNotExist() throws Exception {
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -351,8 +344,7 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain();
persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test
@ -361,8 +353,7 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain();
persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
@Test
@ -371,8 +362,7 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain();
persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
private void runWrongCurrencyTest(Map<String, String> substitutions) throws Exception {
@ -388,8 +378,7 @@ public class DomainRestoreRequestFlowTest extends
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
assertThrows(CurrencyUnitMismatchException.class, () -> runFlow());
}
@Test
@ -411,24 +400,21 @@ public class DomainRestoreRequestFlowTest extends
public void testFailure_feeGivenInWrongScale_v06() throws Exception {
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_06_MAP);
persistPendingDeleteDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception {
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_11_MAP);
persistPendingDeleteDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception {
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_12_MAP);
persistPendingDeleteDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
assertThrows(CurrencyValueScaleException.class, () -> runFlow());
}
@Test
@ -439,70 +425,63 @@ public class DomainRestoreRequestFlowTest extends
.setDeletionTime(clock.nowUtc().plusDays(4))
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.build());
thrown.expect(DomainNotEligibleForRestoreException.class);
runFlow();
assertThrows(DomainNotEligibleForRestoreException.class, () -> runFlow());
}
@Test
public void testFailure_notDeleted() throws Exception {
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(DomainNotEligibleForRestoreException.class);
runFlow();
assertThrows(DomainNotEligibleForRestoreException.class, () -> runFlow());
}
@Test
public void testFailure_fullyDeleted() throws Exception {
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class);
runFlow();
assertThrows(ResourceDoesNotExistException.class, () -> runFlow());
}
@Test
public void testFailure_withChange() throws Exception {
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_change.xml");
thrown.expect(RestoreCommandIncludesChangesException.class);
runFlow();
assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow());
}
@Test
public void testFailure_withAdd() throws Exception {
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_add.xml");
thrown.expect(RestoreCommandIncludesChangesException.class);
runFlow();
assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow());
}
@Test
public void testFailure_withRemove() throws Exception {
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_remove.xml");
thrown.expect(RestoreCommandIncludesChangesException.class);
runFlow();
assertThrows(RestoreCommandIncludesChangesException.class, () -> runFlow());
}
@Test
public void testFailure_withSecDnsExtension() throws Exception {
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_secdns.xml");
thrown.expect(UnimplementedExtensionException.class);
runFlow();
assertThrows(UnimplementedExtensionException.class, () -> runFlow());
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistPendingDeleteDomain();
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
public void testSuccess_superuserUnauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar");
persistPendingDeleteDomain();
thrown.expect(ResourceNotOwnedException.class);
runFlowAssertResponse(loadFile("domain_update_response.xml"));
assertThrows(
ResourceNotOwnedException.class,
() -> runFlowAssertResponse(loadFile("domain_update_response.xml")));
}
@Test
@ -510,8 +489,7 @@ public class DomainRestoreRequestFlowTest extends
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistPendingDeleteDomain();
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
}
@Test
@ -530,8 +508,7 @@ public class DomainRestoreRequestFlowTest extends
persistPendingDeleteDomain();
// Modify the Registrar to block premium names.
persistResource(loadRegistrar("TheRegistrar").asBuilder().setBlockPremiumNames(true).build());
thrown.expect(PremiumNameBlockedException.class);
runFlow();
assertThrows(PremiumNameBlockedException.class, () -> runFlow());
}
@Test
@ -543,8 +520,7 @@ public class DomainRestoreRequestFlowTest extends
.setReservedLists(persistReservedList("tld-reserved", "example,FULLY_BLOCKED"))
.build());
persistPendingDeleteDomain();
thrown.expect(DomainReservedException.class);
runFlow();
assertThrows(DomainReservedException.class, () -> runFlow());
}
@Test
@ -552,8 +528,7 @@ public class DomainRestoreRequestFlowTest extends
createTld("example");
setEppInput("domain_update_restore_request_premium.xml");
persistPendingDeleteDomain();
thrown.expect(FeesRequiredForPremiumNameException.class);
runFlow();
assertThrows(FeesRequiredForPremiumNameException.class, () -> runFlow());
}
@Test

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.DomainResourceSubject.assertAboutDomains;
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 org.joda.money.CurrencyUnit.USD;
@ -406,8 +408,9 @@ public class DomainTransferApproveFlowTest
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_approve_contact_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_approve_contact_authinfo.xml"));
}
@Test
@ -416,89 +419,97 @@ public class DomainTransferApproveFlowTest
persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_approve_domain_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_approve_domain_authinfo.xml"));
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
}
@Test
public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
}
@Test
public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
}
@Test
public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
}
@Test
public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
}
@Test
public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_approve.xml"));
}
@Test
public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("domain_transfer_approve.xml");
assertThrows(
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_approve.xml"));
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("domain_transfer_approve.xml");
assertThrows(
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_approve.xml"));
}
@Test
public void testFailure_deletedDomain() throws Exception {
persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("domain_transfer_approve.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("domain_transfer_approve.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain);
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("domain_transfer_approve.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class,
() -> doFailingTest("domain_transfer_approve.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class);
doSuccessfulTest("tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml");
assertThrows(
NotAuthorizedForTldException.class,
() ->
doSuccessfulTest(
"tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml"));
}
@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.DomainResourceSubject.assertAboutDomains;
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 com.google.common.collect.ImmutableList;
@ -211,8 +213,9 @@ public class DomainTransferCancelFlowTest
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_cancel_contact_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_cancel_contact_authinfo.xml"));
}
@Test
@ -221,89 +224,94 @@ public class DomainTransferCancelFlowTest
domain = persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_cancel_domain_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_cancel_domain_authinfo.xml"));
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
}
@Test
public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
}
@Test
public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
}
@Test
public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
}
@Test
public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
}
@Test
public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
}
@Test
public void testFailure_sponsoringClient() throws Exception {
setClientIdForFlow("TheRegistrar");
thrown.expect(NotTransferInitiatorException.class);
doFailingTest("domain_transfer_cancel.xml");
assertThrows(
NotTransferInitiatorException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
thrown.expect(NotTransferInitiatorException.class);
doFailingTest("domain_transfer_cancel.xml");
assertThrows(
NotTransferInitiatorException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
}
@Test
public void testFailure_deletedDomain() throws Exception {
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("domain_transfer_cancel.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain);
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("domain_transfer_cancel.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_cancel.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
persistResource(
loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class);
doSuccessfulTest("domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml");
assertThrows(
NotAuthorizedForTldException.class,
() ->
doSuccessfulTest("domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml"));
}
@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.persistResource;
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.ResourceDoesNotExistException;
@ -175,8 +177,9 @@ public class DomainTransferQueryFlowTest
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_query_contact_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_query_contact_authinfo.xml"));
}
@Test
@ -185,39 +188,43 @@ public class DomainTransferQueryFlowTest
domain = persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_query_domain_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_query_domain_authinfo.xml"));
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
thrown.expect(NoTransferHistoryToQueryException.class);
doFailingTest("domain_transfer_query.xml");
assertThrows(
NoTransferHistoryToQueryException.class, () -> doFailingTest("domain_transfer_query.xml"));
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
thrown.expect(NotAuthorizedToViewTransferException.class);
doFailingTest("domain_transfer_query.xml");
assertThrows(
NotAuthorizedToViewTransferException.class,
() -> doFailingTest("domain_transfer_query.xml"));
}
@Test
public void testFailure_deletedDomain() throws Exception {
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("domain_transfer_query.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_query.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain);
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("domain_transfer_query.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_query.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@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.DomainResourceSubject.assertAboutDomains;
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 com.google.common.collect.ImmutableSet;
@ -174,8 +176,10 @@ public class DomainTransferRejectFlowTest
public void testFailure_notAuthorizedForTld() throws Exception {
persistResource(
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
thrown.expect(NotAuthorizedForTldException.class);
doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml");
assertThrows(
NotAuthorizedForTldException.class,
() ->
doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml"));
}
@Test
@ -193,8 +197,9 @@ public class DomainTransferRejectFlowTest
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_reject_contact_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_reject_contact_authinfo.xml"));
}
@Test
@ -204,81 +209,84 @@ public class DomainTransferRejectFlowTest
domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_reject_domain_authinfo.xml");
assertThrows(
BadAuthInfoForResourceException.class,
() -> doFailingTest("domain_transfer_reject_domain_authinfo.xml"));
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
NotPendingTransferException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_gainingClient() throws Exception {
setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_unrelatedClient() throws Exception {
setClientIdForFlow("ClientZ");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("domain_transfer_reject.xml");
assertThrows(
ResourceNotOwnedException.class, () -> doFailingTest("domain_transfer_reject.xml"));
}
@Test
public void testFailure_deletedDomain() throws Exception {
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("domain_transfer_reject.xml");
ResourceDoesNotExistException thrown =
expectThrows(
ResourceDoesNotExistException.class, () -> doFailingTest("domain_transfer_reject.xml"));
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain);
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("domain_transfer_reject.xml");
ResourceDoesNotExistException thrown =
expectThrows(
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

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

View file

@ -440,8 +440,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_metadata.xml");
persistReferencedEntities();
persistDomain();
thrown.expect(OnlyToolCanPassMetadataException.class);
runFlow();
assertThrows(OnlyToolCanPassMetadataException.class, () -> runFlow());
}
@Test
@ -795,8 +794,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setDsData(builder.build())
.build());
thrown.expect(TooManyDsRecordsException.class);
runFlow();
assertThrows(TooManyDsRecordsException.class, () -> runFlow());
}
@Test
@ -806,8 +804,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistDomain();
// Modify domain so it has 13 nameservers. We will then try to add one in the test.
modifyDomainToHave13Nameservers();
thrown.expect(TooManyNameserversException.class);
runFlow();
assertThrows(TooManyNameserversException.class, () -> runFlow());
}
@Test
@ -815,25 +812,24 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_wrong_extension.xml");
persistReferencedEntities();
persistDomain();
thrown.expect(UnimplementedExtensionException.class);
runFlow();
assertThrows(UnimplementedExtensionException.class, () -> runFlow());
}
@Test
public void testFailure_neverExisted() throws Exception {
persistReferencedEntities();
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistReferencedEntities();
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage(String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@ -842,9 +838,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistActiveContact("sh8013");
persistActiveContact("mak21");
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(LinkedResourcesDoNotExistException.class);
thrown.expectMessage("(ns2.example.foo)");
runFlow();
LinkedResourcesDoNotExistException thrown =
expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("(ns2.example.foo)");
}
@Test
@ -853,9 +849,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistActiveHost("ns2.example.foo");
persistActiveContact("mak21");
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(LinkedResourcesDoNotExistException.class);
thrown.expectMessage("(sh8013)");
runFlow();
LinkedResourcesDoNotExistException thrown =
expectThrows(LinkedResourcesDoNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("(sh8013)");
}
@Test
@ -871,8 +867,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
DesignatedContact.create(Type.TECH, Key.create(
loadByForeignKey(ContactResource.class, "foo", clock.nowUtc())))))
.build());
thrown.expect(DuplicateContactForRoleException.class);
runFlow();
assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
}
@Test
@ -880,8 +875,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_prohibited_status.xml");
persistReferencedEntities();
persistDomain();
thrown.expect(StatusNotClientSettableException.class);
runFlow();
assertThrows(StatusNotClientSettableException.class, () -> runFlow());
}
@Test
@ -941,8 +935,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build());
thrown.expect(ResourceHasClientUpdateProhibitedException.class);
runFlow();
assertThrows(ResourceHasClientUpdateProhibitedException.class, () -> runFlow());
}
@Test
@ -952,9 +945,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(SERVER_UPDATE_PROHIBITED))
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("serverUpdateProhibited");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("serverUpdateProhibited");
}
@Test
@ -965,9 +958,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setDeletionTime(clock.nowUtc().plusDays(1))
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
thrown.expectMessage("pendingDelete");
runFlow();
ResourceStatusProhibitsOperationException thrown =
expectThrows(ResourceStatusProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("pendingDelete");
}
@Test
@ -975,8 +968,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_duplicate_contact.xml");
persistReferencedEntities();
persistDomain();
thrown.expect(DuplicateContactForRoleException.class);
runFlow();
assertThrows(DuplicateContactForRoleException.class, () -> runFlow());
}
@Test
@ -985,8 +977,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_missing_contact_type.xml");
persistReferencedEntities();
persistDomain();
thrown.expect(MissingContactTypeException.class);
runFlow();
assertThrows(MissingContactTypeException.class, () -> runFlow());
}
@Test
@ -994,8 +985,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
sessionMetadata.setClientId("NewRegistrar");
persistReferencedEntities();
persistDomain();
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
@ -1014,8 +1004,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
loadRegistrar("TheRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
persistReferencedEntities();
persistDomain();
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
assertThrows(NotAuthorizedForTldException.class, () -> runFlow());
}
@Test
@ -1038,8 +1027,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setNameservers(ImmutableSet.of(Key.create(
loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()))))
.build());
thrown.expect(AddRemoveSameValueException.class);
runFlow();
assertThrows(AddRemoveSameValueException.class, () -> runFlow());
}
@Test
@ -1053,8 +1041,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
Key.create(
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())))))
.build());
thrown.expect(AddRemoveSameValueException.class);
runFlow();
assertThrows(AddRemoveSameValueException.class, () -> runFlow());
}
@Test
@ -1067,8 +1054,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact))))
.build());
thrown.expect(MissingAdminContactException.class);
runFlow();
assertThrows(MissingAdminContactException.class, () -> runFlow());
}
@Test
@ -1081,8 +1067,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
DesignatedContact.create(Type.ADMIN, Key.create(sh8013Contact)),
DesignatedContact.create(Type.TECH, Key.create(sh8013Contact))))
.build());
thrown.expect(MissingTechnicalContactException.class);
runFlow();
assertThrows(MissingTechnicalContactException.class, () -> runFlow());
}
@Test
@ -1096,9 +1081,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
clock.advanceOneMilli();
thrown.expect(LinkedResourceInPendingDeleteProhibitsOperationException.class);
thrown.expectMessage("mak21");
runFlow();
LinkedResourceInPendingDeleteProhibitsOperationException thrown =
expectThrows(
LinkedResourceInPendingDeleteProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("mak21");
}
@Test
@ -1113,9 +1099,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
clock.advanceOneMilli();
thrown.expect(LinkedResourceInPendingDeleteProhibitsOperationException.class);
thrown.expectMessage("ns2.example.foo");
runFlow();
LinkedResourceInPendingDeleteProhibitsOperationException thrown =
expectThrows(
LinkedResourceInPendingDeleteProhibitsOperationException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns2.example.foo");
}
@Test
@ -1127,8 +1114,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setAllowedRegistrantContactIds(ImmutableSet.of("contact1234"))
.build());
clock.advanceOneMilli();
thrown.expect(RegistrantNotAllowedException.class);
runFlow();
assertThrows(RegistrantNotAllowedException.class, () -> runFlow());
}
@Test
@ -1140,8 +1126,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
.build());
clock.advanceOneMilli();
thrown.expect(NameserversNotAllowedForTldException.class);
runFlow();
assertThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
}
@Test
@ -1223,8 +1208,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
Registry.get("tld").asBuilder()
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("ns1.example.foo"))
.build());
thrown.expect(NameserversNotSpecifiedForTldWithNameserverWhitelistException.class);
runFlow();
assertThrows(
NameserversNotSpecifiedForTldWithNameserverWhitelistException.class, () -> runFlow());
}
@Test
@ -1252,9 +1237,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList(
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns3.example.foo"))
.build());
thrown.expect(NameserversNotAllowedForDomainException.class);
thrown.expectMessage("ns2.example.foo");
runFlow();
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns2.example.foo");
}
@Test
@ -1269,8 +1254,8 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList(
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo"))
.build());
thrown.expect(NameserversNotSpecifiedForNameserverRestrictedDomainException.class);
runFlow();
assertThrows(
NameserversNotSpecifiedForNameserverRestrictedDomainException.class, () -> runFlow());
}
@Test
@ -1314,9 +1299,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList(
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns3.example.foo"))
.build());
thrown.expect(NameserversNotAllowedForDomainException.class);
thrown.expectMessage("ns2.example.foo");
runFlow();
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns2.example.foo");
}
@Test
@ -1349,9 +1334,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setReservedLists(
persistReservedList("reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo"))
.build());
thrown.expect(NameserversNotAllowedForDomainException.class);
thrown.expectMessage("ns2.example.foo");
runFlow();
NameserversNotAllowedForDomainException thrown =
expectThrows(NameserversNotAllowedForDomainException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns2.example.foo");
}
@Test
@ -1367,9 +1352,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList(
"reserved", "example,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo"))
.build());
thrown.expect(NameserversNotAllowedForTldException.class);
thrown.expectMessage("ns2.example.foo");
runFlow();
NameserversNotAllowedForTldException thrown =
expectThrows(NameserversNotAllowedForTldException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("ns2.example.foo");
}
@Test
@ -1387,8 +1372,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList(
"reserved", "lol,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo"))
.build());
thrown.expect(DomainNotAllowedForTldWithCreateRestrictionException.class);
runFlow();
assertThrows(DomainNotAllowedForTldWithCreateRestrictionException.class, () -> runFlow());
}
@Test
@ -1403,8 +1387,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
persistReservedList(
"reserved", "lol,NAMESERVER_RESTRICTED,ns1.example.foo:ns2.example.foo"))
.build());
thrown.expect(DomainNotAllowedForTldWithCreateRestrictionException.class);
runFlow();
assertThrows(DomainNotAllowedForTldWithCreateRestrictionException.class, () -> runFlow());
}
@Test
@ -1458,8 +1441,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
setEppInput("domain_update_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
persistReferencedEntities();
persistDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
assertThrows(FeesMismatchException.class, () -> runFlow());
}
// 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"));
persistReferencedEntities();
persistDomain();
thrown.expect(FeesRequiredForNonFreeOperationException.class);
runFlow();
assertThrows(FeesRequiredForNonFreeOperationException.class, () -> runFlow());
}
@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.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.JUnitBackports.assertThrows;
import google.registry.flows.ResourceCheckFlowTestCase;
import google.registry.flows.exceptions.TooManyResourceChecksException;
@ -75,8 +76,7 @@ public class HostCheckFlowTest extends ResourceCheckFlowTestCase<HostCheckFlow,
@Test
public void testTooManyIds() throws Exception {
setEppInput("host_check_51.xml");
thrown.expect(TooManyResourceChecksException.class);
runFlow();
assertThrows(TooManyResourceChecksException.class, () -> runFlow());
}
@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.HostResourceSubject.assertAboutHosts;
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.assertNoDnsTasksEnqueued;
@ -125,8 +126,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
createTlds("bar.tld", "tld");
setEppHostCreateInputWithIps("ns1.bar.tld");
thrown.expect(HostNameTooShallowException.class);
runFlow();
assertThrows(HostNameTooShallowException.class, () -> runFlow());
}
@Test
@ -154,8 +154,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
setEppHostCreateInput("ns1.example.tld", null);
createTld("tld");
persistActiveDomain("example.tld");
thrown.expect(SubordinateHostMustHaveIpException.class);
runFlow();
assertThrows(SubordinateHostMustHaveIpException.class, () -> runFlow());
}
@Test
@ -163,17 +162,16 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
setEppHostCreateInputWithIps("ns1.example.external");
createTld("tld");
persistActiveDomain("example.tld");
thrown.expect(UnexpectedExternalHostIpException.class);
runFlow();
assertThrows(UnexpectedExternalHostIpException.class, () -> runFlow());
}
@Test
public void testFailure_superordinateMissing() throws Exception {
setEppHostCreateInput("ns1.example.tld", null);
createTld("tld");
thrown.expect(SuperordinateDomainDoesNotExistException.class);
thrown.expectMessage("(example.tld)");
runFlow();
SuperordinateDomainDoesNotExistException thrown =
expectThrows(SuperordinateDomainDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("(example.tld)");
}
@Test
@ -186,48 +184,49 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.build());
clock.advanceOneMilli();
thrown.expect(SuperordinateDomainInPendingDeleteException.class);
thrown.expectMessage("Superordinate domain for this hostname is in pending delete");
runFlow();
SuperordinateDomainInPendingDeleteException thrown =
expectThrows(SuperordinateDomainInPendingDeleteException.class, () -> runFlow());
assertThat(thrown)
.hasMessageThat()
.contains("Superordinate domain for this hostname is in pending delete");
}
@Test
public void testFailure_alreadyExists() throws Exception {
setEppHostCreateInput("ns1.example.tld", null);
persistActiveHost(getUniqueIdFromCommand());
thrown.expect(ResourceAlreadyExistsException.class);
thrown.expectMessage(
ResourceAlreadyExistsException thrown =
expectThrows(ResourceAlreadyExistsException.class, () -> runFlow());
assertThat(thrown)
.hasMessageThat()
.contains(
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
runFlow();
}
@Test
public void testFailure_nonLowerCaseHostname() throws Exception {
setEppHostCreateInput("ns1.EXAMPLE.tld", null);
thrown.expect(HostNameNotLowerCaseException.class);
runFlow();
assertThrows(HostNameNotLowerCaseException.class, () -> runFlow());
}
@Test
public void testFailure_nonPunyCodedHostname() throws Exception {
setEppHostCreateInput("ns1.çauçalito.みんな", null);
thrown.expect(HostNameNotPunyCodedException.class);
thrown.expectMessage("expected ns1.xn--aualito-txac.xn--q9jyb4c");
runFlow();
HostNameNotPunyCodedException thrown =
expectThrows(HostNameNotPunyCodedException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.xn--q9jyb4c");
}
@Test
public void testFailure_nonCanonicalHostname() throws Exception {
setEppHostCreateInput("ns1.example.tld.", null);
thrown.expect(HostNameNotNormalizedException.class);
runFlow();
assertThrows(HostNameNotNormalizedException.class, () -> runFlow());
}
@Test
public void testFailure_longHostName() throws Exception {
setEppHostCreateInputWithIps("a" + Strings.repeat(".labelpart", 25) + ".tld");
thrown.expect(HostNameTooLongException.class);
runFlow();
assertThrows(HostNameTooLongException.class, () -> runFlow());
}
@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=\"v6\">192.0.2.29</host:addr>\n"
+ "<host:addr ip=\"v6\">1080:0:0:0:8:800:200C:417A</host:addr>");
thrown.expect(IpAddressVersionMismatchException.class);
runFlow();
assertThrows(IpAddressVersionMismatchException.class, () -> runFlow());
}
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 {
createTld("co.uk");
setEppHostCreateInputWithIps("foo.co.uk");
thrown.expect(HostNameTooShallowException.class);
runFlow();
assertThrows(HostNameTooShallowException.class, () -> runFlow());
}
@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.persistResource;
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.TaskQueueHelper.assertNoDnsTasksEnqueued;
@ -83,17 +84,17 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
@Test
public void testFailure_neverExisted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage("(ns1.example.tld)");
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("(ns1.example.tld)");
}
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class);
thrown.expectMessage("(ns1.example.tld)");
runFlow();
ResourceDoesNotExistException thrown =
expectThrows(ResourceDoesNotExistException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("(ns1.example.tld)");
}
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 {
sessionMetadata.setClientId("NewRegistrar");
persistActiveHost("ns1.example.tld");
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
@ -181,8 +181,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
.setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't help.
.setSuperordinateDomain(Key.create(domain))
.build());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
@ -237,8 +236,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
.setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't help.
.setSuperordinateDomain(Key.create(domain))
.build());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
assertThrows(ResourceNotOwnedException.class, () -> runFlow());
}
@Test
@ -248,8 +246,7 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
.setNameservers(ImmutableSet.of(
Key.create(persistActiveHost("ns1.example.tld"))))
.build());
thrown.expect(ResourceToDeleteIsReferencedException.class);
runFlow();
assertThrows(ResourceToDeleteIsReferencedException.class, () -> runFlow());
}
@Test
@ -259,30 +256,27 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
.setNameservers(ImmutableSet.of(
Key.create(persistActiveHost("ns1.example.tld"))))
.build());
thrown.expect(ResourceToDeleteIsReferencedException.class);
runFlow();
assertThrows(ResourceToDeleteIsReferencedException.class, () -> runFlow());
}
@Test
public void testFailure_nonLowerCaseHostname() throws Exception {
setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "NS1.EXAMPLE.NET"));
thrown.expect(HostNameNotLowerCaseException.class);
runFlow();
assertThrows(HostNameNotLowerCaseException.class, () -> runFlow());
}
@Test
public void testFailure_nonPunyCodedHostname() throws Exception {
setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.çauçalito.tld"));
thrown.expect(HostNameNotPunyCodedException.class);
thrown.expectMessage("expected ns1.xn--aualito-txac.tld");
runFlow();
HostNameNotPunyCodedException thrown =
expectThrows(HostNameNotPunyCodedException.class, () -> runFlow());
assertThat(thrown).hasMessageThat().contains("expected ns1.xn--aualito-txac.tld");
}
@Test
public void testFailure_nonCanonicalHostname() throws Exception {
setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld."));
thrown.expect(HostNameNotNormalizedException.class);
runFlow();
assertThrows(HostNameNotNormalizedException.class, () -> runFlow());
}
@Test

View file

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

View file

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

View file

@ -15,6 +15,7 @@
package google.registry.flows.session;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.JUnitBackports.assertThrows;
import google.registry.flows.FlowTestCase;
import google.registry.flows.FlowUtils.NotLoggedInException;
@ -43,7 +44,6 @@ public class LogoutFlowTest extends FlowTestCase<LogoutFlow> {
@Test
public void testFailure() throws Exception {
sessionMetadata.setClientId(null); // Turn off the implicit login
thrown.expect(NotLoggedInException.class);
runFlow();
assertThrows(NotLoggedInException.class, () -> 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.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.beust.jcommander.ParameterException;
@ -131,20 +132,21 @@ public class AllocateDomainCommandTest extends CommandTestCase<AllocateDomainCom
@Test
public void testFailure_notAsSuperuser() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--ids=1-TLD", "--force");
assertThrows(IllegalArgumentException.class, () -> runCommand("--ids=1-TLD", "--force"));
}
@Test
public void testFailure_forceAndDryRunIncompatible() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--ids=1-TLD", "--force", "--dry_run", "--superuser");
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--ids=1-TLD", "--force", "--dry_run", "--superuser"));
}
@Test
public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--ids=1-TLD", "--force", "--unrecognized=foo", "--superuser");
assertThrows(
ParameterException.class,
() -> runCommand("--ids=1-TLD", "--force", "--unrecognized=foo", "--superuser"));
}
@Test

View file

@ -15,6 +15,7 @@
package google.registry.tools;
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.when;
@ -28,9 +29,7 @@ import com.google.api.client.util.store.DataStore;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.io.Serializable;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -61,9 +60,6 @@ public class AuthModuleTest {
return result;
}
}
@Rule public final ExpectedException thrown = ExpectedException.none();
@Test
public void test_clientScopeQualifier() {
AuthModule authModule = new AuthModule();
@ -129,9 +125,8 @@ public class AuthModuleTest {
@Test
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
// 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 org.junit.Before;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
@ -63,9 +62,6 @@ public abstract class CommandTestCase<C extends Command> {
.withTaskQueue()
.build();
@Rule
public final ExpectedException thrown = ExpectedException.none();
@Rule
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.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException;
import google.registry.model.registry.Registry;
@ -83,43 +84,80 @@ public class CreateAnchorTenantCommandTest
@Test
public void testFailure_mainParameter() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--tld=tld", "--client=NewRegistrar", "--superuser",
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld", "foo");
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--tld=tld",
"--client=NewRegistrar",
"--superuser",
"--reason=anchor-tenant-test",
"--contact=jd1234",
"--domain_name=example.tld",
"foo"));
}
@Test
public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--superuser",
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld");
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--superuser",
"--reason=anchor-tenant-test",
"--contact=jd1234",
"--domain_name=example.tld"));
}
@Test
public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--foo=bar", "--client=NewRegistrar", "--superuser",
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld");
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--foo=bar",
"--client=NewRegistrar",
"--superuser",
"--reason=anchor-tenant-test",
"--contact=jd1234",
"--domain_name=example.tld"));
}
@Test
public void testFailure_missingDomainName() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--client=NewRegistrar", "--superuser",
"--reason=anchor-tenant-test", "--contact=jd1234", "foo");
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--superuser",
"--reason=anchor-tenant-test",
"--contact=jd1234",
"foo"));
}
@Test
public void testFailure_missingContact() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--client=NewRegistrar", "--superuser",
"--reason=anchor-tenant-test", "--domain_name=example.tld", "foo");
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--superuser",
"--reason=anchor-tenant-test",
"--domain_name=example.tld",
"foo"));
}
@Test
public void testFailure_notAsSuperuser() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommandForced("--client=NewRegistrar",
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=example.tld");
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--reason=anchor-tenant-test",
"--contact=jd1234",
"--domain_name=example.tld"));
}
}

View file

@ -14,6 +14,8 @@
package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException;
import google.registry.testing.DeterministicStringGenerator;
import org.junit.Before;
@ -58,30 +60,31 @@ public class CreateContactCommandTest extends EppToolCommandTestCase<CreateConta
@Test
public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced();
assertThrows(ParameterException.class, () -> runCommandForced());
}
@Test
public void testFailure_tooManyStreetLines() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--street=\"123 Example Dr.\"",
"--street=\"Floor 3\"",
"--street=\"Suite 100\"",
"--street=\"Office 1\"");
"--street=\"Office 1\""));
}
@Test
public void testFailure_badPhone() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--client=NewRegistrar", "--phone=3");
assertThrows(
ParameterException.class, () -> runCommandForced("--client=NewRegistrar", "--phone=3"));
}
@Test
public void testFailure_badFax() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--client=NewRegistrar", "--fax=3");
assertThrows(
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.loadRegistrar;
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.time.DateTimeZone.UTC;
@ -80,75 +81,96 @@ public class CreateCreditBalanceCommandTest extends CommandTestCase<CreateCredit
@Test
public void testFailure_nonexistentParentRegistrar() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrar FakeRegistrar not found");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--registrar=FakeRegistrar",
"--credit_id=" + creditId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("Registrar FakeRegistrar not found");
}
@Test
public void testFailure_nonexistentCreditId() throws Exception {
long badId = creditId + 1;
thrown.expect(NullPointerException.class);
thrown.expectMessage("ID " + badId);
NullPointerException thrown =
expectThrows(
NullPointerException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + badId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("ID " + badId);
}
@Test
public void testFailure_negativeBalance() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("negative");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + creditId,
"--balance=\"USD -1\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("negative");
}
@Test
public void testFailure_noRegistrar() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--registrar");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--credit_id=" + creditId,
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--registrar");
}
@Test
public void testFailure_noCreditId() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--credit_id");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--credit_id");
}
@Test
public void testFailure_noBalance() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--balance");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + creditId,
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--balance");
}
@Test
public void testFailure_noEffectiveTime() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--effective_time");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--credit_id=" + creditId,
"--balance=\"USD 100\"");
"--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.testing.DatastoreHelper.createTld;
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.time.DateTimeZone.UTC;
@ -93,104 +94,131 @@ public class CreateCreditCommandTest extends CommandTestCase<CreateCreditCommand
@Test
public void testFailure_nonexistentParentRegistrar() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrar FakeRegistrar not found");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--registrar=FakeRegistrar",
"--type=PROMOTION",
"--tld=tld",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("Registrar FakeRegistrar not found");
}
@Test
public void testFailure_nonexistentTld() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("faketld");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--type=PROMOTION",
"--tld=faketld",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("faketld");
}
@Test
public void testFailure_nonexistentType() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("Invalid value for --type");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--type=BADTYPE",
"--tld=tld",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("Invalid value for --type");
}
@Test
public void testFailure_negativeBalance() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("negative");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--type=PROMOTION",
"--tld=tld",
"--balance=\"USD -1\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("negative");
}
@Test
public void testFailure_noRegistrar() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--registrar");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--type=PROMOTION",
"--tld=tld",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--registrar");
}
@Test
public void testFailure_noType() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--type");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--tld=tld",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--type");
}
@Test
public void testFailure_noTld() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--tld");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--type=PROMOTION",
"--balance=\"USD 100\"",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--tld");
}
@Test
public void testFailure_noBalance() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--balance");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--type=PROMOTION",
"--tld=tld",
"--effective_time=2014-11-01T01:02:03Z");
"--effective_time=2014-11-01T01:02:03Z"));
assertThat(thrown).hasMessageThat().contains("--balance");
}
@Test
public void testFailure_noEffectiveTime() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--effective_time");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=TheRegistrar",
"--type=PROMOTION",
"--tld=tld",
"--balance=\"USD 100\"");
"--balance=\"USD 100\""));
assertThat(thrown).hasMessageThat().contains("--effective_time");
}
}

View file

@ -14,6 +14,9 @@
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 google.registry.testing.DeterministicStringGenerator;
import org.junit.Before;
@ -69,64 +72,96 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
@Test
public void testFailure_duplicateDomains() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Duplicate arguments found: \'example.tld\'");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admins=crr-admin",
"--techs=crr-tech",
"example.tld",
"example.tld");
"example.tld"));
assertThat(thrown).hasMessageThat().contains("Duplicate arguments found: \'example.tld\'");
}
@Test
public void testFailure_missingDomain() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("Main parameters are required");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admins=crr-admin",
"--techs=crr-tech");
"--techs=crr-tech"));
assertThat(thrown).hasMessageThat().contains("Main parameters are required");
}
@Test
public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--client");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--admins=crr-admin", "--techs=crr-tech", "--registrant=crr-admin", "example.tld");
"--admins=crr-admin",
"--techs=crr-tech",
"--registrant=crr-admin",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("--client");
}
@Test
public void testFailure_missingRegistrant() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrant must be specified");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar", "--admins=crr-admin", "--techs=crr-tech", "example.tld");
"--client=NewRegistrar",
"--admins=crr-admin",
"--techs=crr-tech",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("Registrant must be specified");
}
@Test
public void testFailure_missingAdmins() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("At least one admin must be specified");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar", "--registrant=crr-admin", "--techs=crr-tech", "example.tld");
"--client=NewRegistrar",
"--registrant=crr-admin",
"--techs=crr-tech",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("At least one admin must be specified");
}
@Test
public void testFailure_missingTechs() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("At least one tech must be specified");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar", "--registrant=crr-admin", "--admins=crr-admin", "example.tld");
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admins=crr-admin",
"example.tld"));
assertThat(thrown).hasMessageThat().contains("At least one tech must be specified");
}
@Test
public void testFailure_tooManyNameServers() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("There can be at most 13 nameservers");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
@ -136,19 +171,23 @@ public class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomain
+ "ns5.zdns.google,ns6.zdns.google,ns7.zdns.google,ns8.zdns.google,"
+ "ns9.zdns.google,ns10.zdns.google,ns11.zdns.google,ns12.zdns.google,"
+ "ns13.zdns.google,ns14.zdns.google",
"example.tld");
"example.tld"));
assertThat(thrown).hasMessageThat().contains("There can be at most 13 nameservers");
}
@Test
public void testFailure_badPeriod() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--period");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--admins=crr-admin",
"--techs=crr-tech",
"--period=x",
"--domain=example.tld");
"--domain=example.tld"));
assertThat(thrown).hasMessageThat().contains("--period");
}
}

View file

@ -14,7 +14,10 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
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 org.junit.Test;
@ -43,18 +46,18 @@ public class CreateHostCommandTest extends EppToolCommandTestCase<CreateHostComm
@Test
public void testFailure_missingHost() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--client=NewRegistrar");
assertThrows(ParameterException.class, () -> runCommandForced("--client=NewRegistrar"));
}
@Test
public void testFailure_invalidIpAddress() throws Exception {
createTld("tld");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("'a.b.c.d' is not an IP string literal.");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--host=example.tld",
"--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.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;
@ -226,45 +227,69 @@ public class CreateLrpTokensCommandTest extends CommandTestCase<CreateLrpTokensC
@Test
public void testFailure_missingAssigneeOrFile() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Exactly one of either assignee or filename must be specified.");
runCommand("--tlds=tld");
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> runCommand("--tlds=tld"));
assertThat(thrown)
.hasMessageThat()
.contains("Exactly one of either assignee or filename must be specified.");
}
@Test
public void testFailure_bothAssigneeAndFile() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Exactly one of either assignee or filename must be specified.");
runCommand("--assignee=domain.tld", "--tlds=tld", "--input=" + assigneeFilePath);
IllegalArgumentException thrown =
expectThrows(
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
public void testFailure_bothMetadataAndFile() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Metadata cannot be specified along with a filename.");
runCommand("--tlds=tld", "--input=" + assigneeFilePath, "--metadata=key=foo");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommand("--tlds=tld", "--input=" + assigneeFilePath, "--metadata=key=foo"));
assertThat(thrown)
.hasMessageThat()
.contains("Metadata cannot be specified along with a filename.");
}
@Test
public void testFailure_bothAssigneeAndMetadataColumns() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Metadata columns cannot be specified along with an assignee.");
runCommand("--assignee=domain.tld", "--tlds=tld", "--metadata_columns=foo=1");
IllegalArgumentException thrown =
expectThrows(
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
public void testFailure_badTld() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("TLDs do not exist: foo");
runCommand("--assignee=domain.tld", "--tlds=foo");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommand("--assignee=domain.tld", "--tlds=foo"));
assertThat(thrown).hasMessageThat().contains("TLDs do not exist: foo");
}
@Test
public void testFailure_oneAssignee_byFile_insufficientMetadata() throws Exception {
Files.asCharSink(assigneeFile, UTF_8).write("domain.tld,foo");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Entry for domain.tld does not have a value for key2 (index 2)");
runCommand("--input=" + assigneeFilePath, "--tlds=tld", "--metadata_columns=key=1,key2=2");
IllegalArgumentException thrown =
expectThrows(
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 {

View file

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

View file

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

View file

@ -21,6 +21,8 @@ import static google.registry.testing.CertificateSamples.SAMPLE_CERT;
import static google.registry.testing.CertificateSamples.SAMPLE_CERT_HASH;
import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.time.DateTimeZone.UTC;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
@ -441,8 +443,10 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
public void testFailure_billingAccountMap_doesNotContainEntryForTldAllowed() throws Exception {
createTlds("foo");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("USD");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -457,7 +461,8 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
assertThat(thrown).hasMessageThat().contains("USD");
}
@Test
@ -695,8 +700,10 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
@Test
public void testFailure_badPhoneNumber() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("phone");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -710,13 +717,16 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
assertThat(thrown).hasMessageThat().contains("phone");
}
@Test
public void testFailure_badPhoneNumber2() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("phone");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -730,7 +740,8 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
assertThat(thrown).hasMessageThat().contains("phone");
}
@Test
@ -757,8 +768,10 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
@Test
public void testFailure_missingRegistrarType() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrar type cannot be null");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -769,12 +782,15 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
assertThat(thrown).hasMessageThat().contains("Registrar type cannot be null");
}
@Test
public void testFailure_invalidRegistrarType() throws Exception {
thrown.expect(ParameterException.class);
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -785,12 +801,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_invalidRegistrarState() throws Exception {
thrown.expect(ParameterException.class);
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -804,12 +822,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_allowedTldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -823,12 +843,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_invalidIpWhitelistFlag() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -842,12 +864,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testSuccess_ipWhitelistFlagWithNull() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -861,12 +885,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_invalidCertFileContents() throws Exception {
thrown.expect(Exception.class);
assertThrows(
Exception.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -880,12 +906,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_invalidFailoverCertFileContents() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -899,12 +927,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_certHashAndCertFile() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -919,13 +949,15 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_certHashNotBase64() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("base64");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -939,13 +971,16 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
assertThat(thrown).hasMessageThat().contains("base64");
}
@Test
public void testFailure_certHashNotA256BitValue() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("256");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -959,13 +994,16 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
assertThat(thrown).hasMessageThat().contains("256");
}
@Test
public void testFailure_missingName() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("--name is a required field");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--password=blobio",
"--registrar_type=REAL",
@ -977,13 +1015,16 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
assertThat(thrown).hasMessageThat().contains("--name is a required field");
}
@Test
public void testFailure_missingPassword() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("--password is a required field");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--registrar_type=REAL",
@ -995,13 +1036,16 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
assertThat(thrown).hasMessageThat().contains("--password is a required field");
}
@Test
public void testFailure_emptyPassword() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("--password is a required field");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=\"\"",
@ -1014,12 +1058,15 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
assertThat(thrown).hasMessageThat().contains("--password is a required field");
}
@Test
public void testFailure_clientIdTooShort() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1032,12 +1079,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"ab");
"ab"));
}
@Test
public void testFailure_clientIdTooLong() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1050,12 +1099,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientabcdefghijk");
"clientabcdefghijk"));
}
@Test
public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class);
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1068,12 +1119,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"--force");
"--force"));
}
@Test
public void testFailure_missingStreetLines() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1085,12 +1138,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"--passcode=01234",
"--icann_referral_email=foo@bar.test",
"clientz");
"clientz"));
}
@Test
public void testFailure_missingCity() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1104,13 +1159,15 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"--passcode=01234",
"--icann_referral_email=foo@bar.test",
"clientz");
"clientz"));
}
@Test
public void testFailure_missingState() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1124,12 +1181,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"--passcode=01234",
"--icann_referral_email=foo@bar.test",
"clientz");
"clientz"));
}
@Test
public void testFailure_missingZip() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1143,12 +1202,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"--passcode=01234",
"--icann_referral_email=foo@bar.test",
"clientz");
"clientz"));
}
@Test
public void testFailure_missingCc() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1162,12 +1223,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--zip 11223",
"--passcode=01234",
"--icann_referral_email=foo@bar.test",
"clientz");
"clientz"));
}
@Test
public void testFailure_invalidCc() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1182,12 +1245,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc USA",
"--passcode=01234",
"--icann_referral_email=foo@bar.test",
"clientz");
"clientz"));
}
@Test
public void testFailure_tooManyStreetLines() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1203,12 +1268,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"--passcode=01234",
"--icann_referral_email=foo@bar.test",
"clientz");
"clientz"));
}
@Test
public void testFailure_tooFewStreetLines() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1221,12 +1288,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--cc US",
"--passcode=01234",
"--icann_referral_email=foo@bar.test",
"clientz");
"clientz"));
}
@Test
public void testFailure_missingIanaIdForRealRegistrar() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1238,12 +1307,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_negativeIanaId() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1256,12 +1327,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_nonIntegerIanaId() throws Exception {
thrown.expect(ParameterException.class);
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1274,12 +1347,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_negativeBillingId() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1293,12 +1368,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_nonIntegerBillingId() throws Exception {
thrown.expect(ParameterException.class);
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1312,12 +1389,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_missingPhonePasscode() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1329,13 +1408,15 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_missingIcannReferralEmail() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("--icann_referral_email");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1347,12 +1428,15 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
assertThat(thrown).hasMessageThat().contains("--icann_referral_email");
}
@Test
public void testFailure_passcodeTooShort() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1365,12 +1449,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_passcodeTooLong() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1383,12 +1469,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_invalidPasscode() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1401,12 +1489,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_twoClientsSpecified() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1420,12 +1510,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--zip 00351",
"--cc US",
"ClientY",
"clientz");
"clientz"));
}
@Test
public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class);
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1439,14 +1531,16 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_alreadyExists() throws Exception {
persistNewRegistrar("existing", "Existing Registrar", Registrar.Type.REAL, 1L);
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Registrar existing already exists");
IllegalStateException thrown =
expectThrows(
IllegalStateException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1459,15 +1553,18 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"existing");
"existing"));
assertThat(thrown).hasMessageThat().contains("Registrar existing already exists");
}
@Test
public void testFailure_registrarNameSimilarToExisting() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("The registrar name tHeRe GiStRaR normalizes "
+ "identically to existing registrar name The Registrar");
// Normalizes identically to "The Registrar" which is created by AppEngineRule.
// Note that "tHeRe GiStRaR" normalizes identically to "The Registrar", which is created by
// AppEngineRule.
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=tHeRe GiStRaR",
"--password=some_password",
@ -1480,14 +1577,20 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
assertThat(thrown)
.hasMessageThat()
.contains(
"The registrar name tHeRe GiStRaR normalizes "
+ "identically to existing registrar name The Registrar");
}
@Test
public void testFailure_clientIdNormalizesToExisting() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("The registrar client identifier theregistrar "
+ "normalizes identically to existing registrar TheRegistrar");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blahhh",
"--password=some_password",
@ -1500,14 +1603,20 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"theregistrar");
"theregistrar"));
assertThat(thrown)
.hasMessageThat()
.contains(
"The registrar client identifier theregistrar "
+ "normalizes identically to existing registrar TheRegistrar");
}
@Test
public void testFailure_clientIdIsInvalidFormat() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"Client identifier (.L33T) can only contain lowercase letters, numbers, and hyphens");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--name=blahhh",
"--password=some_password",
@ -1520,12 +1629,18 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
".L33T");
".L33T"));
assertThat(thrown)
.hasMessageThat()
.contains(
"Client identifier (.L33T) can only contain lowercase letters, numbers, and hyphens");
}
@Test
public void testFailure_phone() throws Exception {
thrown.expect(ParameterException.class);
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1539,12 +1654,14 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
@Test
public void testFailure_fax() throws Exception {
thrown.expect(ParameterException.class);
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--name=blobio",
"--password=some_password",
@ -1558,6 +1675,6 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
"--state MA",
"--zip 00351",
"--cc US",
"clientz");
"clientz"));
}
}

View file

@ -14,6 +14,8 @@
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.Mockito.verify;
@ -54,9 +56,12 @@ public class CreateRegistrarGroupsCommandTest extends
@Test
public void test_throwsExceptionForNonExistentRegistrar() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"Could not load registrar with id FakeRegistrarThatDefinitelyDoesNotExist");
runCommandForced("FakeRegistrarThatDefinitelyDoesNotExist");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> 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.persistReservedList;
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 org.joda.time.DateTimeZone.UTC;
@ -90,9 +91,11 @@ public class CreateReservedListCommandTest extends
public void testFailure_reservedListWithThatNameAlreadyExists() throws Exception {
ReservedList rl = persistReservedList("xn--q9jyb4c_foo", "jones,FULLY_BLOCKED");
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setReservedLists(rl).build());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("A reserved list already exists by this name");
runCommandForced("--name=xn--q9jyb4c_foo", "--input=" + reservedTermsPath);
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--name=xn--q9jyb4c_foo", "--input=" + reservedTermsPath));
assertThat(thrown).hasMessageThat().contains("A reserved list already exists by this name");
}
@Test

View file

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

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

View file

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

View file

@ -14,6 +14,8 @@
package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException;
import org.junit.Test;
@ -57,33 +59,48 @@ public class DeleteHostCommandTest extends EppToolCommandTestCase<DeleteHostComm
@Test
public void testFailure_noReason() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--client=NewRegistrar", "--host=ns1.example.tld", "--force");
assertThrows(
ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--host=ns1.example.tld", "--force"));
}
@Test
public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--host=ns1.example.tld", "--force", "--reason=Test");
assertThrows(
ParameterException.class,
() -> runCommand("--host=ns1.example.tld", "--force", "--reason=Test"));
}
@Test
public void testFailure_missingHostName() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--client=NewRegistrar", "--force", "--reason=Test");
assertThrows(
ParameterException.class,
() -> runCommand("--client=NewRegistrar", "--force", "--reason=Test"));
}
@Test
public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class);
assertThrows(
ParameterException.class,
() ->
runCommand(
"--client=NewRegistrar", "--host=ns1.example.tld", "--force", "--reason=Test", "--foo");
"--client=NewRegistrar",
"--host=ns1.example.tld",
"--force",
"--reason=Test",
"--foo"));
}
@Test
public void testFailure_mainParameter() throws Exception {
thrown.expect(ParameterException.class);
assertThrows(
ParameterException.class,
() ->
runCommand(
"--client=NewRegistrar", "--host=ns1.example.tld", "--force", "--reason=Test", "foo");
"--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.persistPremiumList;
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.label.PremiumList;
@ -48,9 +49,11 @@ public class DeletePremiumListCommandTest extends CommandTestCase<DeletePremiumL
@Test
public void testFailure_whenPremiumListDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Cannot delete the premium list foo because it doesn't exist.");
runCommandForced("--name=foo");
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> runCommandForced("--name=foo"));
assertThat(thrown)
.hasMessageThat()
.contains("Cannot delete the premium list foo because it doesn't exist.");
}
@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.persistReservedList;
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.label.ReservedList;
@ -47,9 +48,11 @@ public class DeleteReservedListCommandTest extends CommandTestCase<DeleteReserve
public void testFailure_whenReservedListDoesNotExist() throws Exception {
String expectedError =
"Cannot delete the reserved list doesntExistReservedList because it doesn't exist.";
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(expectedError);
runCommandForced("--name=doesntExistReservedList");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--name=doesntExistReservedList"));
assertThat(thrown).hasMessageThat().contains(expectedError);
}
@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.persistDeletedDomain;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.base.Ascii;
@ -57,35 +58,30 @@ public class DeleteTldCommandTest extends CommandTestCase<DeleteTldCommand> {
runCommandForced("--tld=" + TLD_TEST);
Registry.get(TLD_REAL);
thrown.expect(RegistryNotFoundException.class);
Registry.get(TLD_TEST);
assertThrows(RegistryNotFoundException.class, () -> Registry.get(TLD_TEST));
}
@Test
public void testFailure_whenTldDoesNotExist() throws Exception {
thrown.expect(RegistryNotFoundException.class);
runCommandForced("--tld=nonexistenttld");
assertThrows(RegistryNotFoundException.class, () -> runCommandForced("--tld=nonexistenttld"));
}
@Test
public void testFailure_whenTldIsReal() throws Exception {
thrown.expect(IllegalStateException.class);
runCommandForced("--tld=" + TLD_REAL);
assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_REAL));
}
@Test
public void testFailure_whenDomainsArePresent() throws Exception {
persistDeletedDomain("domain." + TLD_TEST, DateTime.parse("2000-01-01TZ"));
thrown.expect(IllegalStateException.class);
runCommandForced("--tld=" + TLD_TEST);
assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_TEST));
}
@Test
public void testFailure_whenRegistrarLinksToTld() throws Exception {
allowRegistrarAccess("TheRegistrar", TLD_TEST);
thrown.expect(IllegalStateException.class);
runCommandForced("--tld=" + TLD_TEST);
assertThrows(IllegalStateException.class, () -> runCommandForced("--tld=" + TLD_TEST));
}
}

View file

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

View file

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

View file

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

View file

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

View file

@ -14,6 +14,9 @@
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.Parameters;
import google.registry.tools.server.ToolsTestData;
@ -71,8 +74,10 @@ public class EppToolCommandTest extends EppToolCommandTestCase<EppToolCommand> {
@Test
public void testFailure_nonexistentClientId() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("fakeclient");
runCommandForced("--client=fakeclient", "fake-xml");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--client=fakeclient", "fake-xml"));
assertThat(thrown).hasMessageThat().contains("fakeclient");
}
}

View file

@ -14,6 +14,7 @@
package google.registry.tools;
import static google.registry.testing.JUnitBackports.assertThrows;
import static java.nio.charset.StandardCharsets.UTF_8;
import com.beust.jcommander.ParameterException;
@ -77,19 +78,20 @@ public class ExecuteEppCommandTest extends EppToolCommandTestCase<ExecuteEppComm
@Test
public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--force", "foo.xml");
assertThrows(ParameterException.class, () -> runCommand("--force", "foo.xml"));
}
@Test
public void testFailure_forceAndDryRunIncompatible() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--client=NewRegistrar", "--force", "--dry_run", eppFile);
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--client=NewRegistrar", "--force", "--dry_run", eppFile));
}
@Test
public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--client=NewRegistrar", "--unrecognized=foo", "--force", "foo.xml");
assertThrows(
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.newSunriseApplication;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC;
@ -320,19 +321,16 @@ public class GenerateAuctionDataCommandTest extends CommandTestCase<GenerateAuct
@Test
public void testFailure_missingTldName() throws Exception {
thrown.expect(ParameterException.class);
runCommand();
assertThrows(ParameterException.class, () -> runCommand());
}
@Test
public void testFailure_tooManyParameters() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("xn--q9jyb4c", "foobar");
assertThrows(IllegalArgumentException.class, () -> runCommand("xn--q9jyb4c", "foobar"));
}
@Test
public void testFailure_nonexistentTld() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("foobarbaz");
assertThrows(IllegalArgumentException.class, () -> 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.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.time.DateTimeZone.UTC;
@ -203,13 +204,11 @@ public class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsRep
@Test
public void testFailure_tldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--tld=foobar");
assertThrows(IllegalArgumentException.class, () -> runCommand("--tld=foobar"));
}
@Test
public void testFailure_missingTldParameter() throws Exception {
thrown.expect(ParameterException.class);
runCommand("");
assertThrows(ParameterException.class, () -> runCommand(""));
}
}

View file

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

View file

@ -14,10 +14,13 @@
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.newDomainApplication;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
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 com.beust.jcommander.ParameterException;
@ -60,9 +63,9 @@ public class GetApplicationIdsCommandTest extends CommandTestCase<GetApplication
@Test
public void testFailure_tldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Domain name is not under a recognized TLD");
runCommand("example.foo");
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> runCommand("example.foo"));
assertThat(thrown).hasMessageThat().contains("Domain name is not under a recognized TLD");
}
@Test
@ -75,8 +78,7 @@ public class GetApplicationIdsCommandTest extends CommandTestCase<GetApplication
@Test
public void testFailure_noDomainName() throws Exception {
thrown.expect(ParameterException.class);
runCommand();
assertThrows(ParameterException.class, () -> runCommand());
}
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.persistDeletedContact;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException;
@ -79,8 +80,7 @@ public class GetContactCommandTest extends CommandTestCase<GetContactCommand> {
@Test
public void testFailure_noContact() throws Exception {
thrown.expect(ParameterException.class);
runCommand();
assertThrows(ParameterException.class, () -> runCommand());
}
@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.persistDeletedDomain;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException;
@ -95,8 +96,7 @@ public class GetDomainCommandTest extends CommandTestCase<GetDomainCommand> {
@Test
public void testFailure_noDomainName() throws Exception {
thrown.expect(ParameterException.class);
runCommand();
assertThrows(ParameterException.class, () -> runCommand());
}
@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.persistDeletedHost;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException;
@ -106,7 +107,6 @@ public class GetHostCommandTest extends CommandTestCase<GetHostCommand> {
@Test
public void testFailure_noHostName() throws Exception {
thrown.expect(ParameterException.class);
runCommand();
assertThrows(ParameterException.class, () -> runCommand());
}
}

View file

@ -14,9 +14,11 @@
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.persistActiveDomainApplication;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.googlecode.objectify.Key;
import google.registry.model.domain.DomainApplication;
@ -79,8 +81,10 @@ public class GetLrpTokenCommandTest extends CommandTestCase<GetLrpTokenCommand>
@Test
public void testFailure_noArgs() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Exactly one of either token or assignee must be specified.");
runCommand();
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> 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;
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 org.junit.Test;
@ -34,21 +38,20 @@ public class GetRegistrarCommandTest extends CommandTestCase<GetRegistrarCommand
@Test
public void testFailure_registrarDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrar with id ClientZ does not exist");
runCommand("ClientZ");
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> runCommand("ClientZ"));
assertThat(thrown).hasMessageThat().contains("Registrar with id ClientZ does not exist");
}
@Test
public void testFailure_noRegistrarName() throws Exception {
thrown.expect(ParameterException.class);
runCommand();
assertThrows(ParameterException.class, () -> runCommand());
}
@Test
public void testFailure_oneRegistrarDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrar with id ClientZ does not exist");
runCommand("NewRegistrar", "ClientZ");
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> runCommand("NewRegistrar", "ClientZ"));
assertThat(thrown).hasMessageThat().contains("Registrar with id ClientZ does not exist");
}
}

View file

@ -14,6 +14,7 @@
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.persistActiveContact;
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.persistDeletedDomain;
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 com.beust.jcommander.ParameterException;
@ -68,10 +71,16 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
@Test
public void testFailure_domain_oneDoesNotExist() throws Exception {
persistActiveDomain("example.tld");
thrown.expect(NullPointerException.class);
thrown.expectMessage("Could not load resource for key: Key<?>(DomainBase(\"4-TLD\"))");
NullPointerException thrown =
expectThrows(
NullPointerException.class,
() ->
runCommand(
"agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw", "agR0ZXN0chULEgpEb21haW5CYXNlIgU0LVRMRAw");
"agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw",
"agR0ZXN0chULEgpEb21haW5CYXNlIgU0LVRMRAw"));
assertThat(thrown)
.hasMessageThat()
.contains("Could not load resource for key: Key<?>(DomainBase(\"4-TLD\"))");
}
@Test
@ -111,11 +120,16 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
@Test
public void testFailure_contact_oneDoesNotExist() throws Exception {
persistActiveContact("sh8013");
thrown.expect(NullPointerException.class);
thrown.expectMessage("Could not load resource for key: Key<?>(ContactResource(\"3-ROID\"))");
NullPointerException thrown =
expectThrows(
NullPointerException.class,
() ->
runCommand(
"agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw",
"agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjMtUk9JRAw");
"agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjMtUk9JRAw"));
assertThat(thrown)
.hasMessageThat()
.contains("Could not load resource for key: Key<?>(ContactResource(\"3-ROID\"))");
}
@Test
@ -155,11 +169,16 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
@Test
public void testFailure_host_oneDoesNotExist() throws Exception {
persistActiveHost("ns1.example.tld");
thrown.expect(NullPointerException.class);
thrown.expectMessage("Could not load resource for key: Key<?>(HostResource(\"3-ROID\"))");
NullPointerException thrown =
expectThrows(
NullPointerException.class,
() ->
runCommand(
"agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw",
"agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjMtUk9JRAw");
"agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjMtUk9JRAw"));
assertThat(thrown)
.hasMessageThat()
.contains("Could not load resource for key: Key<?>(HostResource(\"3-ROID\"))");
}
@Test
@ -186,21 +205,25 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
@Test
public void testFailure_keyDoesNotExist() throws Exception {
thrown.expect(NullPointerException.class);
thrown.expectMessage("Could not load resource for key: Key<?>(DomainBase(\"2-TLD\"))");
runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw");
NullPointerException thrown =
expectThrows(
NullPointerException.class,
() -> runCommand("agR0ZXN0chULEgpEb21haW5CYXNlIgUyLVRMRAw"));
assertThat(thrown)
.hasMessageThat()
.contains("Could not load resource for key: Key<?>(DomainBase(\"2-TLD\"))");
}
@Test
public void testFailure_nonsenseKey() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Could not parse Reference");
runCommand("agR0ZXN0chULEgpEb21haW5CYXN");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class, () -> runCommand("agR0ZXN0chULEgpEb21haW5CYXN"));
assertThat(thrown).hasMessageThat().contains("Could not parse Reference");
}
@Test
public void testFailure_noParameters() throws Exception {
thrown.expect(ParameterException.class);
runCommand();
assertThrows(ParameterException.class, () -> runCommand());
}
}

View file

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

View file

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

View file

@ -14,6 +14,9 @@
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.collect.ImmutableList;
import google.registry.tools.server.ListDomainsAction;
@ -43,8 +46,10 @@ public class ListDomainsCommandTest extends ListObjectsCommandTestCase<ListDomai
@Test
public void test_tldsParamTooLong() throws Exception {
String tldsParam = "--tld=foo,bar" + Strings.repeat(",baz", 300);
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Total length of TLDs is too long for URL parameter");
runCommand(tldsParam);
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> 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(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
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.persistNewRegistrar;
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 google.registry.model.host.HostResource;
@ -32,7 +34,6 @@ import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -44,10 +45,6 @@ public class MutatingCommandTest {
public final AppEngineRule appEngine = AppEngineRule.builder()
.withDatastore()
.build();
@Rule
public final ExpectedException thrown = ExpectedException.none();
Registrar registrar1;
Registrar registrar2;
Registrar newRegistrar1;
@ -298,8 +295,7 @@ public class MutatingCommandTest {
stageEntityChange(null, null);
}
};
thrown.expect(IllegalArgumentException.class);
command.init();
assertThrows(IllegalArgumentException.class, () -> command.init());
}
@Test
@ -313,9 +309,11 @@ public class MutatingCommandTest {
.build());
}
};
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Cannot apply multiple changes for the same entity");
command.init();
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> command.init());
assertThat(thrown)
.hasMessageThat()
.contains("Cannot apply multiple changes for the same entity");
}
@Test
@ -326,9 +324,11 @@ public class MutatingCommandTest {
stageEntityChange(host1, host2);
}
};
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Both entity versions in an update must have the same Key.");
command.init();
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> command.init());
assertThat(thrown)
.hasMessageThat()
.contains("Both entity versions in an update must have the same Key.");
}
@Test
@ -339,9 +339,11 @@ public class MutatingCommandTest {
stageEntityChange(registrar1, registrar2);
}
};
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Both entity versions in an update must have the same Key.");
command.init();
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> command.init());
assertThat(thrown)
.hasMessageThat()
.contains("Both entity versions in an update must have the same Key.");
}
@Test
@ -352,9 +354,11 @@ public class MutatingCommandTest {
stageEntityChange(host1, registrar1);
}
};
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Both entity versions in an update must have the same Key.");
command.init();
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> command.init());
assertThat(thrown)
.hasMessageThat()
.contains("Both entity versions in an update must have the same Key.");
}
@Test
@ -367,9 +371,9 @@ public class MutatingCommandTest {
};
command.init();
persistResource(newHost1);
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Entity changed since init() was called.");
command.execute();
IllegalStateException thrown =
expectThrows(IllegalStateException.class, () -> command.execute());
assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
}
@Test
@ -382,9 +386,9 @@ public class MutatingCommandTest {
};
command.init();
persistResource(newHost1);
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Entity changed since init() was called.");
command.execute();
IllegalStateException thrown =
expectThrows(IllegalStateException.class, () -> command.execute());
assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
}
@Test
@ -397,9 +401,9 @@ public class MutatingCommandTest {
};
command.init();
persistResource(newHost1);
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Entity changed since init() was called.");
command.execute();
IllegalStateException thrown =
expectThrows(IllegalStateException.class, () -> command.execute());
assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
}
@Test
@ -412,8 +416,8 @@ public class MutatingCommandTest {
};
command.init();
deleteResource(host1);
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Entity changed since init() was called.");
command.execute();
IllegalStateException thrown =
expectThrows(IllegalStateException.class, () -> command.execute());
assertThat(thrown).hasMessageThat().contains("Entity changed since init() was called.");
}
}

View file

@ -15,10 +15,9 @@
package google.registry.tools;
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.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -26,13 +25,9 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class RegistryToolEnvironmentTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testGet_withoutSetup_throws() throws Exception {
thrown.expect(IllegalStateException.class);
RegistryToolEnvironment.get();
assertThrows(IllegalStateException.class, () -> RegistryToolEnvironment.get());
}
@Test
@ -72,16 +67,18 @@ public class RegistryToolEnvironmentTest {
@Test
public void testFromArgs_envFlagAfterCommandName_getsIgnored() throws Exception {
thrown.expect(IllegalArgumentException.class);
RegistryToolEnvironment.parseFromArgs(new String[] {
"registrar_activity_report",
"-e", "1406851199"});
assertThrows(
IllegalArgumentException.class,
() ->
RegistryToolEnvironment.parseFromArgs(
new String[] {"registrar_activity_report", "-e", "1406851199"}));
}
@Test
public void testFromArgs_missingEnvironmentFlag_throwsIae() throws Exception {
thrown.expect(IllegalArgumentException.class);
RegistryToolEnvironment.parseFromArgs(new String[] {});
assertThrows(
IllegalArgumentException.class,
() -> RegistryToolEnvironment.parseFromArgs(new String[] {}));
}
@Test
@ -106,7 +103,8 @@ public class RegistryToolEnvironmentTest {
@Test
public void testFromArgs_badName_throwsIae() throws Exception {
thrown.expect(IllegalArgumentException.class);
RegistryToolEnvironment.parseFromArgs(new String[] { "-e", "alphaville" });
assertThrows(
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.persistPremiumList;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.time.DateTimeZone.UTC;
import com.beust.jcommander.ParameterException;
@ -203,132 +204,168 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
@Test
public void testFailure_missingIpWhitelist() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("option is required: -w, --ip_whitelist");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--registrar=blobio",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename());
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("option is required: -w, --ip_whitelist");
}
@Test
public void testFailure_missingRegistrar() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("option is required: -r, --registrar");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename());
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("option is required: -r, --registrar");
}
@Test
public void testFailure_missingCertificateFile() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("option is required: -c, --certfile");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--dns_writers=VoidDnsWriter",
"--registrar=blobio");
"--ip_whitelist=1.1.1.1", "--dns_writers=VoidDnsWriter", "--registrar=blobio"));
assertThat(thrown).hasMessageThat().contains("option is required: -c, --certfile");
}
@Test
public void testFailure_missingDnsWriter() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("option is required: --dns_writers");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--certfile=" + getCertFilename(),
"--registrar=blobio");
"--registrar=blobio"));
assertThat(thrown).hasMessageThat().contains("option is required: --dns_writers");
}
@Test
public void testFailure_invalidCert() throws Exception {
thrown.expect(CertificateParsingException.class);
thrown.expectMessage("No X509Certificate found");
CertificateParsingException thrown =
expectThrows(
CertificateParsingException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--registrar=blobio",
"--dns_writers=VoidDnsWriter",
"--certfile=/dev/null");
"--certfile=/dev/null"));
assertThat(thrown).hasMessageThat().contains("No X509Certificate found");
}
@Test
public void testFailure_invalidRegistrar() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrar name is invalid");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--registrar=3blobio",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename());
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("Registrar name is invalid");
}
@Test
public void testFailure_invalidDnsWriter() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid DNS writer name(s) specified: [InvalidDnsWriter]");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--registrar=blobio",
"--dns_writers=InvalidDnsWriter",
"--certfile=" + getCertFilename());
"--certfile=" + getCertFilename()));
assertThat(thrown)
.hasMessageThat()
.contains("Invalid DNS writer name(s) specified: [InvalidDnsWriter]");
}
@Test
public void testFailure_registrarTooShort() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrar name is invalid");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--registrar=bl",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename());
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("Registrar name is invalid");
}
@Test
public void testFailure_registrarTooLong() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrar name is invalid");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--registrar=blobiotoooolong",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename());
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("Registrar name is invalid");
}
@Test
public void testFailure_registrarInvalidCharacter() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrar name is invalid");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--registrar=blo#bio",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename());
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("Registrar name is invalid");
}
@Test
public void testFailure_invalidPremiumList() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("The premium list 'foo' doesn't exist");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--registrar=blobio",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename(),
"--premium_list=foo");
"--premium_list=foo"));
assertThat(thrown).hasMessageThat().contains("The premium list 'foo' doesn't exist");
}
@Test
public void testFailure_tldExists() throws Exception {
createTld("blobio-sunrise");
thrown.expect(IllegalStateException.class);
thrown.expectMessage("TLD 'blobio-sunrise' already exists");
IllegalStateException thrown =
expectThrows(
IllegalStateException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--registrar=blobio",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename());
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("TLD 'blobio-sunrise' already exists");
}
@Test
@ -338,12 +375,15 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
.setRegistrarName("blobio-1")
.build();
persistResource(registrar);
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Registrar blobio-1 already exists");
IllegalStateException thrown =
expectThrows(
IllegalStateException.class,
() ->
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--registrar=blobio",
"--dns_writers=VoidDnsWriter",
"--certfile=" + getCertFilename());
"--certfile=" + getCertFilename()));
assertThat(thrown).hasMessageThat().contains("Registrar blobio-1 already exists");
}
}

View file

@ -14,11 +14,13 @@
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.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import com.beust.jcommander.ParameterException;
import com.google.common.collect.ImmutableSet;
@ -150,46 +152,58 @@ public class UniformRapidSuspensionCommandTest
@Test
public void testFailure_locksToPreserveWithoutUndo() throws Exception {
persistActiveDomain("evil.tld");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("--undo");
runCommandForced("--domain_name=evil.tld", "--locks_to_preserve=serverDeleteProhibited");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--domain_name=evil.tld", "--locks_to_preserve=serverDeleteProhibited"));
assertThat(thrown).hasMessageThat().contains("--undo");
}
@Test
public void testFailure_domainNameRequired() throws Exception {
persistActiveDomain("evil.tld");
thrown.expect(ParameterException.class);
thrown.expectMessage("--domain_name");
runCommandForced("--hosts=urs1.example.com,urs2.example.com");
ParameterException thrown =
expectThrows(
ParameterException.class,
() -> runCommandForced("--hosts=urs1.example.com,urs2.example.com"));
assertThat(thrown).hasMessageThat().contains("--domain_name");
}
@Test
public void testFailure_extraFieldInDsData() throws Exception {
persistActiveDomain("evil.tld");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Incorrect fields on --dsdata JSON");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--domain_name=evil.tld",
"--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1,\"digest\":\"abc\",\"foo\":1}");
"--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1,\"digest\":\"abc\",\"foo\":1}"));
assertThat(thrown).hasMessageThat().contains("Incorrect fields on --dsdata JSON");
}
@Test
public void testFailure_missingFieldInDsData() throws Exception {
persistActiveDomain("evil.tld");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Incorrect fields on --dsdata JSON");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--domain_name=evil.tld",
"--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1}");
"--dsdata={\"keyTag\":1,\"alg\":1,\"digestType\":1}"));
assertThat(thrown).hasMessageThat().contains("Incorrect fields on --dsdata JSON");
}
@Test
public void testFailure_malformedDsData() throws Exception {
persistActiveDomain("evil.tld");
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid --dsdata JSON");
runCommandForced(
"--domain_name=evil.tld",
"--dsdata=[1,2,3]");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommandForced("--domain_name=evil.tld", "--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.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows;
import static org.joda.time.DateTimeZone.UTC;
@ -270,16 +271,25 @@ public class UpdateApplicationStatusCommandTest
@Test
public void testFailure_applicationDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommandForced("--ids=555-Q9JYB4C", "--msg=\"Application rejected\"", "--status=REJECTED");
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--ids=555-Q9JYB4C", "--msg=\"Application rejected\"", "--status=REJECTED"));
}
@Test
public void testFailure_historyClientIdDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("fakeclient");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--history_client_id=fakeclient", "--ids=2-Q9JYB4C", "--msg=Ignored", "--status=REJECTED");
"--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.persistResource;
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.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
@ -131,12 +132,14 @@ public class UpdateClaimsNoticeCommandTest extends CommandTestCase<UpdateClaimsN
@Test
public void testFailure_badClaimsNotice() throws Exception {
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommand(
"--id=1-Q9JYB4C",
"--tcn_id=foobarbaz",
"--expiration_time=2010-08-16T09:00:00.0Z",
"--accepted_time=2009-08-16T09:00:00.0Z");
"--accepted_time=2009-08-16T09:00:00.0Z"));
}
@Test
@ -160,12 +163,13 @@ public class UpdateClaimsNoticeCommandTest extends CommandTestCase<UpdateClaimsN
domainApplication = persistResource(domainApplication.asBuilder()
.setEncodedSignedMarks(ImmutableList.of(EncodedSignedMark.create("base64", "AAAAA")))
.build());
thrown.expect(IllegalArgumentException.class);
assertThrows(
IllegalArgumentException.class,
() ->
runCommand(
"--id=1-Q9JYB4C",
"--tcn_id=370d0b7c9223372036854775807",
"--expiration_time=2010-08-16T09:00:00.0Z",
"--accepted_time=2009-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.testing.DatastoreHelper.createTld;
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 google.registry.model.common.Cursor;
@ -110,14 +112,17 @@ public class UpdateCursorsCommandTest extends CommandTestCase<UpdateCursorsComma
@Test
public void testFailure_badTld() throws Exception {
thrown.expect(RegistryNotFoundException.class);
runCommandForced("--type=brda", "--timestamp=1984-12-18T00:00:00Z", "bar");
assertThrows(
RegistryNotFoundException.class,
() -> runCommandForced("--type=brda", "--timestamp=1984-12-18T00:00:00Z", "bar"));
}
@Test
public void testFailure_badCursorType() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("Invalid value for --type parameter");
runCommandForced("--type=rbda", "--timestamp=1984-12-18T00:00:00Z", "foo");
ParameterException thrown =
expectThrows(
ParameterException.class,
() -> runCommandForced("--type=rbda", "--timestamp=1984-12-18T00:00:00Z", "foo"));
assertThat(thrown).hasMessageThat().contains("Invalid value for --type parameter");
}
}

View file

@ -192,34 +192,45 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
@Test
public void testFailure_duplicateDomains() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Duplicate arguments found");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--registrant=crr-admin",
"--password=2fooBAR",
"example.tld",
"example.tld");
"example.tld"));
assertThat(thrown).hasMessageThat().contains("Duplicate arguments found");
}
@Test
public void testFailure_missingDomain() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("Main parameters are required");
runCommandForced("--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR");
ParameterException thrown =
expectThrows(
ParameterException.class,
() ->
runCommandForced(
"--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR"));
assertThat(thrown).hasMessageThat().contains("Main parameters are required");
}
@Test
public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class);
thrown.expectMessage("--client");
runCommandForced("--registrant=crr-admin", "--password=2fooBAR", "example.tld");
ParameterException thrown =
expectThrows(
ParameterException.class,
() -> runCommandForced("--registrant=crr-admin", "--password=2fooBAR", "example.tld"));
assertThat(thrown).hasMessageThat().contains("--client");
}
@Test
public void testFailure_addTooManyNameServers() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("You can add at most 13 nameservers");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--add_nameservers=ns1.zdns.google,ns2.zdns.google,ns3.zdns.google,ns4.zdns.google,"
@ -229,93 +240,149 @@ public class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomain
"--add_admins=crr-admin2",
"--add_techs=crr-tech2",
"--add_statuses=serverDeleteProhibited",
"example.tld");
"example.tld"));
assertThat(thrown).hasMessageThat().contains("You can add at most 13 nameservers");
}
@Test
public void testFailure_providedNameserversAndAddNameservers() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("If you provide the nameservers flag, "
+ "you cannot use the add_nameservers and remove_nameservers flags.");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--add_nameservers=ns1.zdns.google",
"--nameservers=ns2.zdns.google,ns3.zdns.google",
"example.tld");
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.contains(
"If you provide the nameservers flag, "
+ "you cannot use the add_nameservers and remove_nameservers flags.");
}
@Test
public void testFailure_providedNameserversAndRemoveNameservers() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("If you provide the nameservers flag, "
+ "you cannot use the add_nameservers and remove_nameservers flags.");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--remove_nameservers=ns1.zdns.google",
"--nameservers=ns2.zdns.google,ns3.zdns.google",
"example.tld");
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.contains(
"If you provide the nameservers flag, "
+ "you cannot use the add_nameservers and remove_nameservers flags.");
}
@Test
public void testFailure_providedAdminsAndAddAdmins() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"If you provide the admins flag, you cannot use the add_admins and remove_admins flags.");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar", "--add_admins=crr-admin2", "--admins=crr-admin2", "example.tld");
"--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
public void testFailure_providedAdminsAndRemoveAdmins() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"If you provide the admins flag, you cannot use the add_admins and remove_admins flags.");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--remove_admins=crr-admin2",
"--admins=crr-admin2",
"example.tld");
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
"If you provide the admins flag, "
+ "you cannot use the add_admins and remove_admins flags.");
}
@Test
public void testFailure_providedTechsAndAddTechs() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"If you provide the techs flag, you cannot use the add_techs and remove_techs flags.");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar", "--add_techs=crr-tech2", "--techs=crr-tech2", "example.tld");
"--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
public void testFailure_providedTechsAndRemoveTechs() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"If you provide the techs flag, you cannot use the add_techs and remove_techs flags.");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar", "--remove_techs=crr-tech2", "--techs=crr-tech2", "example.tld");
"--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
public void testFailure_providedStatusesAndAddStatuses() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("If you provide the statuses flag, "
+ "you cannot use the add_statuses and remove_statuses flags.");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--add_statuses=serverHold",
"--statuses=crr-serverHold",
"example.tld");
"example.tld"));
assertThat(thrown)
.hasMessageThat()
.contains(
"If you provide the statuses flag, "
+ "you cannot use the add_statuses and remove_statuses flags.");
}
@Test
public void testFailure_providedStatusesAndRemoveStatuses() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("If you provide the statuses flag, "
+ "you cannot use the add_statuses and remove_statuses flags.");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--remove_statuses=serverHold",
"--statuses=crr-serverHold",
"example.tld");
"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.loadRegistrar;
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 com.beust.jcommander.ParameterException;
@ -70,9 +72,11 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
.setIanaIdentifier(null)
.setPhonePasscode(null)
.build());
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("--passcode is required for REAL registrars.");
runCommand("--registrar_type=REAL", "--iana_id=1000", "--force", "NewRegistrar");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() -> runCommand("--registrar_type=REAL", "--iana_id=1000", "--force", "NewRegistrar"));
assertThat(thrown).hasMessageThat().contains("--passcode is required for REAL registrars.");
}
@Test
@ -217,14 +221,17 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
public void testFailure_billingAccountMap_doesNotContainEntryForTldAllowed() throws Exception {
createTlds("foo");
assertThat(loadRegistrar("NewRegistrar").getBillingAccountMap()).isEmpty();
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("USD");
IllegalArgumentException thrown =
expectThrows(
IllegalArgumentException.class,
() ->
runCommand(
"--billing_account_map=JPY=789xyz",
"--allowed_tlds=foo",
"--force",
"--registrar_type=REAL",
"NewRegistrar");
"NewRegistrar"));
assertThat(thrown).hasMessageThat().contains("USD");
}
@Test
@ -276,11 +283,15 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
.setAmount(Money.parse("USD 10.00"))
.build());
assertThat(registrar.getBillingMethod()).isEqualTo(BillingMethod.EXTERNAL);
thrown.expect(IllegalStateException.class);
thrown.expectMessage(
"Refusing to change billing method on Registrar 'NewRegistrar' from EXTERNAL to BRAINTREE"
+ " because current balance is non-zero: {USD=USD 10.00}");
runCommand("--billing_method=braintree", "--force", "NewRegistrar");
IllegalStateException thrown =
expectThrows(
IllegalStateException.class,
() -> 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
@ -437,174 +448,267 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test
public void testFailure_invalidRegistrarType() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--registrar_type=INVALID_TYPE", "--force", "NewRegistrar");
assertThrows(
ParameterException.class,
() -> runCommand("--registrar_type=INVALID_TYPE", "--force", "NewRegistrar"));
}
@Test
public void testFailure_invalidRegistrarState() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--registrar_state=INVALID_STATE", "--force", "NewRegistrar");
assertThrows(
ParameterException.class,
() -> runCommand("--registrar_state=INVALID_STATE", "--force", "NewRegistrar"));
}
@Test
public void testFailure_negativeIanaId() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--iana_id=-1", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--iana_id=-1", "--force", "NewRegistrar"));
}
@Test
public void testFailure_nonIntegerIanaId() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--iana_id=ABC123", "--force", "NewRegistrar");
assertThrows(
ParameterException.class, () -> runCommand("--iana_id=ABC123", "--force", "NewRegistrar"));
}
@Test
public void testFailure_negativeBillingId() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--billing_id=-1", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--billing_id=-1", "--force", "NewRegistrar"));
}
@Test
public void testFailure_nonIntegerBillingId() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--billing_id=ABC123", "--force", "NewRegistrar");
assertThrows(
ParameterException.class,
() -> runCommand("--billing_id=ABC123", "--force", "NewRegistrar"));
}
@Test
public void testFailure_passcodeTooShort() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--passcode=0123", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--passcode=0123", "--force", "NewRegistrar"));
}
@Test
public void testFailure_passcodeTooLong() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--passcode=012345", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--passcode=012345", "--force", "NewRegistrar"));
}
@Test
public void testFailure_invalidPasscode() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--passcode=code1", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--passcode=code1", "--force", "NewRegistrar"));
}
@Test
public void testFailure_allowedTldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--allowed_tlds=foobar", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--allowed_tlds=foobar", "--force", "NewRegistrar"));
}
@Test
public void testFailure_addAllowedTldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--add_allowed_tlds=foobar", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--add_allowed_tlds=foobar", "--force", "NewRegistrar"));
}
@Test
public void testFailure_allowedTldsAndAddAllowedTlds() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--allowed_tlds=bar", "--add_allowed_tlds=foo", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() ->
runCommand("--allowed_tlds=bar", "--add_allowed_tlds=foo", "--force", "NewRegistrar"));
}
@Test
public void testFailure_invalidIpWhitelist() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--ip_whitelist=foobarbaz", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() -> runCommand("--ip_whitelist=foobarbaz", "--force", "NewRegistrar"));
}
@Test
public void testFailure_invalidCertFileContents() throws Exception {
thrown.expect(Exception.class);
runCommand("--cert_file=" + writeToTmpFile("ABCDEF"), "--force", "NewRegistrar");
assertThrows(
Exception.class,
() -> runCommand("--cert_file=" + writeToTmpFile("ABCDEF"), "--force", "NewRegistrar"));
}
@Test
public void testFailure_certHashAndCertFile() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--cert_file=" + getCertFilename(), "--cert_hash=ABCDEF", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() ->
runCommand(
"--cert_file=" + getCertFilename(),
"--cert_hash=ABCDEF",
"--force",
"NewRegistrar"));
}
@Test
public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--force");
assertThrows(ParameterException.class, () -> runCommand("--force"));
}
@Test
public void testFailure_missingStreetLines() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--city Brooklyn", "--state NY", "--zip 11223", "--cc US", "--force",
"NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() ->
runCommand(
"--city Brooklyn",
"--state NY",
"--zip 11223",
"--cc US",
"--force",
"NewRegistrar"));
}
@Test
public void testFailure_missingCity() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"",
"--state NY", "--zip 11223", "--cc US", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() ->
runCommand(
"--street=\"1234 Main St\"",
"--street \"4th Floor\"",
"--street \"Suite 1\"",
"--state NY",
"--zip 11223",
"--cc US",
"--force",
"NewRegistrar"));
}
@Test
public void testFailure_missingState() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"",
"--city Brooklyn", "--zip 11223", "--cc US", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() ->
runCommand(
"--street=\"1234 Main St\"",
"--street \"4th Floor\"",
"--street \"Suite 1\"",
"--city Brooklyn",
"--zip 11223",
"--cc US",
"--force",
"NewRegistrar"));
}
@Test
public void testFailure_missingZip() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"",
"--city Brooklyn", "--state NY", "--cc US", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() ->
runCommand(
"--street=\"1234 Main St\"",
"--street \"4th Floor\"",
"--street \"Suite 1\"",
"--city Brooklyn",
"--state NY",
"--cc US",
"--force",
"NewRegistrar"));
}
@Test
public void testFailure_missingCc() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"",
"--city Brooklyn", "--state NY", "--zip 11223", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() ->
runCommand(
"--street=\"1234 Main St\"",
"--street \"4th Floor\"",
"--street \"Suite 1\"",
"--city Brooklyn",
"--state NY",
"--zip 11223",
"--force",
"NewRegistrar"));
}
@Test
public void testFailure_missingInvalidCc() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--street=\"1234 Main St\"", "--street \"4th Floor\"", "--street \"Suite 1\"",
"--city Brooklyn", "--state NY", "--zip 11223", "--cc USA", "--force", "NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() ->
runCommand(
"--street=\"1234 Main St\"",
"--street \"4th Floor\"",
"--street \"Suite 1\"",
"--city Brooklyn",
"--state NY",
"--zip 11223",
"--cc USA",
"--force",
"NewRegistrar"));
}
@Test
public void testFailure_tooManyStreetLines() throws Exception {
thrown.expect(IllegalArgumentException.class);
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");
assertThrows(
IllegalArgumentException.class,
() ->
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
public void testFailure_tooFewStreetLines() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommand("--street", "--city Brooklyn", "--state NY", "--zip 11223", "--cc USA", "--force",
"NewRegistrar");
assertThrows(
IllegalArgumentException.class,
() ->
runCommand(
"--street",
"--city Brooklyn",
"--state NY",
"--zip 11223",
"--cc USA",
"--force",
"NewRegistrar"));
}
@Test
public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class);
runCommand("--force", "--unrecognized_flag=foo", "NewRegistrar");
assertThrows(
ParameterException.class,
() -> runCommand("--force", "--unrecognized_flag=foo", "NewRegistrar"));
}
@Test
public void testFailure_doesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Registrar ClientZ not found");
runCommand("--force", "ClientZ");
IllegalArgumentException thrown =
expectThrows(IllegalArgumentException.class, () -> runCommand("--force", "ClientZ"));
assertThat(thrown).hasMessageThat().contains("Registrar ClientZ not found");
}
@Test
public void testFailure_registrarNameSimilarToExisting() throws Exception {
thrown.expect(IllegalArgumentException.class);
// Normalizes identically to "The Registrar" which is created by AppEngineRule.
runCommand("--name tHeRe GiStRaR", "--force", "NewRegistrar");
// Note that "tHeRe GiStRaR" normalizes identically to "The Registrar", which is created by
// AppEngineRule.
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 google.registry.model.registry.label.ReservationType.FULLY_BLOCKED;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.collect.ImmutableList;
@ -92,8 +93,11 @@ public class UpdateReservedListCommandTest extends
public void testFailure_reservedListDoesntExist() throws Exception {
String errorMessage =
"Could not update reserved list xn--q9jyb4c_poobah because it doesn't exist.";
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(errorMessage);
runCommand("--force", "--name=xn--q9jyb4c_poobah", "--input=" + reservedTermsPath);
IllegalArgumentException thrown =
expectThrows(
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;
import static google.registry.testing.JUnitBackports.assertThrows;
import com.beust.jcommander.ParameterException;
import org.junit.Test;
@ -57,69 +59,123 @@ public class UpdateServerLocksCommandTest extends EppToolCommandTestCase<UpdateS
@Test
public void testFailure_applyAllRemoveOne_failsDueToOverlap() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test",
"--domain_name=example.tld", "--apply=all", "--remove=serverRenewProhibited");
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=true",
"--reason=Test",
"--domain_name=example.tld",
"--apply=all",
"--remove=serverRenewProhibited"));
}
@Test
public void testFailure_illegalStatus() throws Exception {
// The EPP status is a valid one by RFC, but invalid for this command.
thrown.expect(IllegalArgumentException.class);
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test",
"--domain_name=example.tld", "--apply=clientRenewProhibited");
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=true",
"--reason=Test",
"--domain_name=example.tld",
"--apply=clientRenewProhibited"));
}
@Test
public void testFailure_unrecognizedStatus() throws Exception {
// Handles a status passed to the command that doesn't correspond to any
// EPP-valid status.
thrown.expect(IllegalArgumentException.class);
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test",
"--domain_name=example.tld", "--apply=foo");
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=true",
"--reason=Test",
"--domain_name=example.tld",
"--apply=foo"));
}
@Test
public void testFailure_mainParameter() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test",
"--domain_name=example.tld", "example2.tld", "--apply=serverRenewProhibited");
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=true",
"--reason=Test",
"--domain_name=example.tld",
"example2.tld",
"--apply=serverRenewProhibited"));
}
@Test
public void testFailure_noOp() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommandForced("--client=NewRegistrar", "--domain_name=example.tld", "--apply=all",
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--domain_name=example.tld",
"--apply=all",
"--remove=serverRenewProhibited,serverTransferProhibited,"
+ "serverDeleteProhibited,serverUpdateProhibited,serverHold",
"--registrar_request=true", "--reason=Test");
"--registrar_request=true",
"--reason=Test"));
}
@Test
public void testFailure_missingClientId() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--domain_name=example.tld", "--registrar_request=true",
"--apply=serverRenewProhibited", "--reason=Test");
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--domain_name=example.tld",
"--registrar_request=true",
"--apply=serverRenewProhibited",
"--reason=Test"));
}
@Test
public void testFailure_unknownFlag() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--client=NewRegistrar", "--registrar_request=true", "--reason=Test",
"--domain_name=example.tld", "--apply=serverRenewProhibited", "--foo=bar");
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=true",
"--reason=Test",
"--domain_name=example.tld",
"--apply=serverRenewProhibited",
"--foo=bar"));
}
@Test
public void testFailure_noReasonWhenNotRegistrarRequested() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommandForced("--client=NewRegistrar", "--registrar_request=false",
"--domain_name=example.tld", "--apply=serverRenewProhibited");
assertThrows(
IllegalArgumentException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--registrar_request=false",
"--domain_name=example.tld",
"--apply=serverRenewProhibited"));
}
@Test
public void testFailure_missingRegistrarRequest() throws Exception {
thrown.expect(ParameterException.class);
runCommandForced("--client=NewRegistrar", "--reason=Test",
"--domain_name=example.tld", "--apply=serverRenewProhibited");
assertThrows(
ParameterException.class,
() ->
runCommandForced(
"--client=NewRegistrar",
"--reason=Test",
"--domain_name=example.tld",
"--apply=serverRenewProhibited"));
}
}

View file

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

View file

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

View file

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

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

View file

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