mirror of
https://github.com/google/nomulus.git
synced 2025-08-05 01:11:50 +02:00
Automatically refactor more exception testing to use new JUnit rules
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=179072309
This commit is contained in:
parent
d5d29959b4
commit
9157930983
100 changed files with 3900 additions and 3192 deletions
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
|
||||
runFlow();
|
||||
ResourceAlreadyExistsException thrown =
|
||||
expectThrows(ResourceAlreadyExistsException.class, () -> runFlow());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains(
|
||||
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
|
||||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue