Move thrown.expect() right before the throwing statement

aka regexing for fun and profit.

This also makes sure that there are no statements after the
throwing statement, since these would be dead code. There
were a surprising number of places with assertions after
the throw, and none of these are actually triggered in tests
ever. When I found these, I replaced them with try/catch/rethrow
which makes the assertions actually happen:

before:

// This is the ExceptionRule that checks EppException marshaling
thrown.expect(FooException.class);
doThrowingThing();
assertSomething();  // Dead code!

after:

try {
  doThrowingThing();
  assertWithMessage("...").fail();
} catch (FooException e) {
  assertSomething();
  // For EppExceptions:
  assertAboutEppExceptins().that(e).marshalsToXml();
}

To make this work, I added EppExceptionSubject.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=135793407
This commit is contained in:
cgoldfeder 2016-10-11 07:19:48 -07:00 committed by Ben McIlwain
parent cb8320ff40
commit f3a0b78145
62 changed files with 519 additions and 450 deletions

View file

@ -120,8 +120,7 @@ public class DnsMessageTransportTest {
when(mockSocket.getOutputStream()).thenReturn(new ByteArrayOutputStream());
thrown.expect(EOFException.class);
Message expectedQuery = new Message();
resolver.send(expectedQuery);
resolver.send(new Message());
}
@Test

View file

@ -105,29 +105,29 @@ public class DatastoreBackupInfoTest {
@Test
public void testFailure_missingName() throws Exception {
thrown.expect(NullPointerException.class);
backupEntity.removeProperty("name");
thrown.expect(NullPointerException.class);
new DatastoreBackupInfo(persistEntity(backupEntity));
}
@Test
public void testFailure_missingKinds() throws Exception {
thrown.expect(NullPointerException.class);
backupEntity.removeProperty("kinds");
thrown.expect(NullPointerException.class);
new DatastoreBackupInfo(persistEntity(backupEntity));
}
@Test
public void testFailure_missingStartTime() throws Exception {
thrown.expect(NullPointerException.class);
backupEntity.removeProperty("start_time");
thrown.expect(NullPointerException.class);
new DatastoreBackupInfo(persistEntity(backupEntity));
}
@Test
public void testFailure_badGcsFilenameFormat() throws Exception {
thrown.expect(IllegalArgumentException.class);
backupEntity.setProperty("gs_handle", new Text("foo"));
thrown.expect(IllegalArgumentException.class);
new DatastoreBackupInfo(persistEntity(backupEntity));
}
}

View file

@ -16,6 +16,7 @@ package google.registry.export;
import static com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistActiveDomainApplication;
@ -31,13 +32,11 @@ import com.google.appengine.tools.cloudstorage.ListResult;
import com.google.common.base.Splitter;
import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldType;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeResponse;
import google.registry.testing.mapreduce.MapreduceTestCase;
import java.io.FileNotFoundException;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -48,9 +47,6 @@ public class ExportDomainListsActionTest extends MapreduceTestCase<ExportDomainL
private GcsService gcsService;
@Rule
public final ExceptionRule thrown = new ExceptionRule();
@Before
public void init() {
createTld("tld");
@ -94,12 +90,15 @@ public class ExportDomainListsActionTest extends MapreduceTestCase<ExportDomainL
assertThat(Splitter.on('\n').splitToList(tlds)).containsExactly("onetwo.tld", "rudnitzky.tld");
// Make sure that the test TLD file wasn't written out.
GcsFilename nonexistentFile = new GcsFilename("outputbucket", "testtld.txt");
thrown.expect(FileNotFoundException.class);
readGcsFile(gcsService, nonexistentFile);
ListResult ls = gcsService.list("outputbucket", ListOptions.DEFAULT);
assertThat(ls.next().getName()).isEqualTo("tld.txt");
// Make sure that no other files were written out.
assertThat(ls.hasNext()).isFalse();
try {
readGcsFile(gcsService, nonexistentFile);
assertWithMessage("Expected FileNotFoundException to be thrown").fail();
} catch (FileNotFoundException e) {
ListResult ls = gcsService.list("outputbucket", ListOptions.DEFAULT);
assertThat(ls.next().getName()).isEqualTo("tld.txt");
// Make sure that no other files were written out.
assertThat(ls.hasNext()).isFalse();
}
}
@Test

View file

@ -14,6 +14,9 @@
package google.registry.export;
import static com.google.common.base.Throwables.getRootCause;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.export.ExportReservedTermsAction.EXPORT_MIME_TYPE;
import static google.registry.export.ExportReservedTermsAction.RESERVED_TERMS_FILENAME;
import static google.registry.testing.DatastoreHelper.createTld;
@ -30,13 +33,10 @@ import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableSet;
import com.google.common.net.MediaType;
import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.RegistryNotFoundException;
import google.registry.model.registry.label.ReservedList;
import google.registry.request.Response;
import google.registry.storage.drive.DriveConnection;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
import google.registry.testing.InjectRule;
import java.io.IOException;
import org.junit.Before;
import org.junit.Rule;
@ -54,12 +54,6 @@ public class ExportReservedTermsActionTest {
.withDatastore()
.build();
@Rule
public final ExceptionRule thrown = new ExceptionRule();
@Rule
public final InjectRule inject = new InjectRule();
@Mock
private DriveConnection driveConnection;
@ -117,29 +111,40 @@ public class ExportReservedTermsActionTest {
@Test
public void test_uploadFileToDrive_failsWhenDriveFolderIdIsNull() throws Exception {
thrown.expectRootCause(NullPointerException.class, "No drive folder associated with this TLD");
persistResource(Registry.get("tld").asBuilder().setDriveFolderId(null).build());
runAction("tld");
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
try {
runAction("tld");
assertWithMessage("Expected RuntimeException to be thrown").fail();
} catch (RuntimeException e) {
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
assertThat(getRootCause(e)).hasMessage("No drive folder associated with this TLD");
}
}
@Test
public void test_uploadFileToDrive_failsWhenDriveCannotBeReached() throws Exception {
thrown.expectRootCause(IOException.class, "errorMessage");
when(driveConnection.createOrUpdateFile(
anyString(),
any(MediaType.class),
anyString(),
any(byte[].class))).thenThrow(new IOException("errorMessage"));
runAction("tld");
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
try {
runAction("tld");
assertWithMessage("Expected RuntimeException to be thrown").fail();
} catch (RuntimeException e) {
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
assertThat(getRootCause(e)).hasMessage("errorMessage");
}
}
@Test
public void test_uploadFileToDrive_failsWhenTldDoesntExist() throws Exception {
thrown.expectRootCause(
RegistryNotFoundException.class, "No registry object found for fakeTld");
runAction("fakeTld");
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
try {
runAction("fakeTld");
assertWithMessage("Expected RuntimeException to be thrown").fail();
} catch (RuntimeException e) {
verify(response).setStatus(SC_INTERNAL_SERVER_ERROR);
assertThat(getRootCause(e)).hasMessage("No registry object found for fakeTld");
}
}
}

View file

@ -118,8 +118,8 @@ public abstract class ResourceFlowTestCase<F extends Flow, R extends EppResource
@Test
public void testRequiresLogin() throws Exception {
thrown.expect(CommandUseErrorException.class);
sessionMetadata.setClientId(null);
thrown.expect(CommandUseErrorException.class);
runFlow();
}

View file

@ -65,10 +65,10 @@ public class ContactCreateFlowTest
@Test
public void testFailure_alreadyExists() throws Exception {
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(
ResourceAlreadyExistsException.class,
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
persistActiveContact(getUniqueIdFromCommand());
runFlow();
}
@ -80,15 +80,15 @@ public class ContactCreateFlowTest
@Test
public void testFailure_nonAsciiInIntAddress() throws Exception {
thrown.expect(BadInternationalizedPostalInfoException.class);
setEppInput("contact_create_hebrew_int.xml");
thrown.expect(BadInternationalizedPostalInfoException.class);
runFlow();
}
@Test
public void testFailure_declineDisclosure() throws Exception {
thrown.expect(DeclineContactDisclosureFieldDisallowedPolicyException.class);
setEppInput("contact_create_decline_disclosure.xml");
thrown.expect(DeclineContactDisclosureFieldDisallowedPolicyException.class);
runFlow();
}
}

View file

@ -46,11 +46,11 @@ public class ContactDeleteFlowTest
private void doFailingStatusTest(StatusValue statusValue, Class<? extends Exception> exception)
throws Exception {
thrown.expect(exception);
persistResource(
newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(statusValue))
.build());
thrown.expect(exception);
runFlow();
}
@ -85,10 +85,10 @@ public class ContactDeleteFlowTest
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
runFlow();
}
@ -112,9 +112,9 @@ public class ContactDeleteFlowTest
@Test
public void testFailure_unauthorizedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
sessionMetadata.setClientId("NewRegistrar");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
}

View file

@ -171,10 +171,10 @@ public class ContactInfoFlowTest extends ResourceFlowTestCase<ContactInfoFlow, C
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistContactResource(false);
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistContactResource(false);
runFlow();
}
}

View file

@ -124,89 +124,89 @@ public class ContactTransferApproveFlowTest
@Test
public void testFailure_badContactPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_approve_with_authinfo.xml");
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
}
@Test
public void testFailure_clientApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
}
@Test
public void testFailure_clientRejected() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
}
@Test
public void testFailure_clientCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
}
@Test
public void testFailure_serverApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
}
@Test
public void testFailure_serverCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_approve.xml");
}
@Test
public void testFailure_gainingClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("contact_transfer_approve.xml");
}
@Test
public void testFailure_unrelatedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
setClientIdForFlow("ClientZ");
thrown.expect(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,
String.format("(%s)", getUniqueIdFromCommand()));
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
doFailingTest("contact_transfer_approve.xml");
}
@Test
public void testFailure_nonexistentContact() throws Exception {
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
deleteResource(contact);
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("contact_transfer_approve.xml");
}
}

View file

@ -112,87 +112,87 @@ public class ContactTransferCancelFlowTest
@Test
public void testFailure_badContactPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_cancel_with_authinfo.xml");
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
}
@Test
public void testFailure_clientApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
}
@Test
public void testFailure_clientRejected() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
}
@Test
public void testFailure_clientCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
}
@Test
public void testFailure_serverApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
}
@Test
public void testFailure_serverCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_cancel.xml");
}
@Test
public void testFailure_sponsoringClient() throws Exception {
thrown.expect(NotTransferInitiatorException.class);
setClientIdForFlow("TheRegistrar");
thrown.expect(NotTransferInitiatorException.class);
doFailingTest("contact_transfer_cancel.xml");
}
@Test
public void testFailure_unrelatedClient() throws Exception {
thrown.expect(NotTransferInitiatorException.class);
setClientIdForFlow("ClientZ");
thrown.expect(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,
String.format("(%s)", getUniqueIdFromCommand()));
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
doFailingTest("contact_transfer_cancel.xml");
}
@Test
public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact);
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
deleteResource(contact);
doFailingTest("contact_transfer_cancel.xml");
}
}

View file

@ -133,54 +133,54 @@ public class ContactTransferQueryFlowTest
@Test
public void testFailure_badContactPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_query_with_authinfo.xml");
}
@Test
public void testFailure_badContactRoid() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Set the contact to a different ROID, but don't persist it; this is just so the substitution
// code above will write the wrong ROID into the file.
contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build();
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_query_with_roid.xml");
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
thrown.expect(NoTransferHistoryToQueryException.class);
changeTransferStatus(null);
thrown.expect(NoTransferHistoryToQueryException.class);
doFailingTest("contact_transfer_query.xml");
}
@Test
public void testFailure_unrelatedClient() throws Exception {
thrown.expect(NotAuthorizedToViewTransferException.class);
setClientIdForFlow("ClientZ");
thrown.expect(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,
String.format("(%s)", getUniqueIdFromCommand()));
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
doFailingTest("contact_transfer_query.xml");
}
@Test
public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact);
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
deleteResource(contact);
doFailingTest("contact_transfer_query.xml");
}
}

View file

@ -122,87 +122,87 @@ public class ContactTransferRejectFlowTest
@Test
public void testFailure_badPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_reject_with_authinfo.xml");
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
}
@Test
public void testFailure_clientApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
}
@Test
public void testFailure_clientRejected() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
}
@Test
public void testFailure_clientCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
}
@Test
public void testFailure_serverApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
}
@Test
public void testFailure_serverCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("contact_transfer_reject.xml");
}
@Test
public void testFailure_gainingClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("contact_transfer_reject.xml");
}
@Test
public void testFailure_unrelatedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
setClientIdForFlow("ClientZ");
thrown.expect(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,
String.format("(%s)", getUniqueIdFromCommand()));
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
doFailingTest("contact_transfer_reject.xml");
}
@Test
public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact);
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
deleteResource(contact);
doFailingTest("contact_transfer_reject.xml");
}
}

View file

@ -111,12 +111,12 @@ public class ContactTransferRequestFlowTest
@Test
public void testFailure_badPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("contact_transfer_request.xml");
}
@ -152,7 +152,6 @@ public class ContactTransferRequestFlowTest
@Test
public void testFailure_pending() throws Exception {
thrown.expect(AlreadyPendingTransferException.class);
contact = persistResource(
contact.asBuilder()
.setTransferData(contact.getTransferData().asBuilder()
@ -160,32 +159,33 @@ public class ContactTransferRequestFlowTest
.setPendingTransferExpirationTime(clock.nowUtc().plusDays(1))
.build())
.build());
thrown.expect(AlreadyPendingTransferException.class);
doFailingTest("contact_transfer_request.xml");
}
@Test
public void testFailure_sponsoringClient() throws Exception {
thrown.expect(ObjectAlreadySponsoredException.class);
setClientIdForFlow("TheRegistrar");
thrown.expect(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,
String.format("(%s)", getUniqueIdFromCommand()));
contact = persistResource(
contact.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
doFailingTest("contact_transfer_request.xml");
}
@Test
public void testFailure_nonexistentContact() throws Exception {
deleteResource(contact);
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
deleteResource(contact);
doFailingTest("contact_transfer_request.xml");
}
}

View file

@ -158,18 +158,18 @@ public class ContactUpdateFlowTest
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistDeletedContact(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
runFlow();
}
@Test
public void testFailure_clientProhibitedStatusValue() throws Exception {
thrown.expect(StatusNotClientSettableException.class);
setEppInput("contact_update_prohibited_status.xml");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(StatusNotClientSettableException.class);
runFlow();
}
@ -186,9 +186,9 @@ public class ContactUpdateFlowTest
@Test
public void testFailure_unauthorizedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
sessionMetadata.setClientId("NewRegistrar");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
}
@ -220,21 +220,21 @@ public class ContactUpdateFlowTest
@Test
public void testFailure_clientUpdateProhibited() throws Exception {
thrown.expect(ResourceHasClientUpdateProhibitedException.class);
persistResource(
newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build());
thrown.expect(ResourceHasClientUpdateProhibitedException.class);
runFlow();
}
@Test
public void testFailure_serverUpdateProhibited() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistResource(
newContactResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED))
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@ -246,25 +246,25 @@ public class ContactUpdateFlowTest
@Test
public void testFailure_nonAsciiInIntAddress() throws Exception {
thrown.expect(BadInternationalizedPostalInfoException.class);
setEppInput("contact_update_hebrew_int.xml");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(BadInternationalizedPostalInfoException.class);
runFlow();
}
@Test
public void testFailure_declineDisclosure() throws Exception {
thrown.expect(DeclineContactDisclosureFieldDisallowedPolicyException.class);
setEppInput("contact_update_decline_disclosure.xml");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(DeclineContactDisclosureFieldDisallowedPolicyException.class);
runFlow();
}
@Test
public void testFailure_addRemoveSameValue() throws Exception {
thrown.expect(AddRemoveSameValueEppException.class);
setEppInput("contact_update_add_remove_same.xml");
persistActiveContact(getUniqueIdFromCommand());
thrown.expect(AddRemoveSameValueEppException.class);
runFlow();
}
}

View file

@ -115,12 +115,12 @@ public class ClaimsCheckFlowTest extends ResourceFlowTestCase<ClaimsCheckFlow, D
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
DatastoreHelper.persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
}

View file

@ -487,13 +487,13 @@ public class DomainAllocateFlowTest
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
setupDomainApplication("tld", TldState.QUIET_PERIOD);
DatastoreHelper.persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
}
@ -502,8 +502,8 @@ public class DomainAllocateFlowTest
setupDomainApplication("tld", TldState.GENERAL_AVAILABILITY);
clock.advanceOneMilli();
setEppInput("domain_allocate_no_nameservers.xml");
thrown.expect(OnlySuperuserCanAllocateException.class);
assertTransactionalFlow(true);
thrown.expect(OnlySuperuserCanAllocateException.class);
runFlow(CommitMode.LIVE, UserPrivileges.NORMAL);
}
}

View file

@ -17,6 +17,7 @@ package google.registry.flows.domain;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.io.BaseEncoding.base16;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
@ -30,6 +31,7 @@ import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainApplicationSubject.assertAboutApplications;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.EUR;
@ -961,7 +963,6 @@ public class DomainApplicationCreateFlowTest
@Test
public void testFailure_landrushLrpApplication_usedToken() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
createTld("tld", TldState.LANDRUSH);
persistResource(Registry.get("tld").asBuilder()
.setLrpTldStates(ImmutableSet.of(TldState.LANDRUSH))
@ -975,6 +976,7 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_landrush_lrp.xml");
persistContactsAndHosts();
clock.advanceOneMilli();
thrown.expect(BadAuthInfoForResourceException.class);
runFlow();
}
@ -1514,14 +1516,12 @@ public class DomainApplicationCreateFlowTest
clock.advanceOneMilli();
persistActiveDomain(getUniqueIdFromCommand());
try {
// This fails fast and throws DomainAlreadyExistsException from init() as a special case.
thrown.expect(
ResourceAlreadyExistsException.class,
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
runFlow();
assertWithMessage("Expected ResourceAlreadyExistsException to be thrown").fail();
} catch (ResourceAlreadyExistsException e) {
assertThat(e.isFailfast()).isTrue();
throw e;
assertAboutEppExceptions().that(e).marshalsToXml().and().hasMessage(
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
}
}
@ -1583,15 +1583,13 @@ public class DomainApplicationCreateFlowTest
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.addGracePeriod(GracePeriod.create(gracePeriodStatus, END_OF_TIME, "", null))
.build());
// This doesn't fail fast, so it throws the regular ResourceAlreadyExistsException from run().
thrown.expect(
ResourceAlreadyExistsException.class,
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
try {
runFlow();
assertWithMessage("Expected ResourceAlreadyExistsException to be thrown").fail();
} catch (ResourceAlreadyExistsException e) {
assertThat(e.isFailfast()).isFalse();
throw e;
assertAboutEppExceptions().that(e).marshalsToXml().and().hasMessage(
String.format("Object with given ID (%s) already exists", getUniqueIdFromCommand()));
}
}

View file

@ -127,28 +127,27 @@ public class DomainApplicationDeleteFlowTest
@Test
public void testFailure_existedButWasDeleted() throws Exception {
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistResource(newDomainApplication("example.tld").asBuilder()
.setRepoId("1-TLD")
.setDeletionTime(clock.nowUtc().minusSeconds(1))
.build());
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
sessionMetadata.setClientId("NewRegistrar");
persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
persistResource(
@ -156,6 +155,7 @@ public class DomainApplicationDeleteFlowTest
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
}
@ -173,12 +173,12 @@ public class DomainApplicationDeleteFlowTest
public void testFailure_sunriseDuringLandrush() throws Exception {
createTld("tld", TldState.LANDRUSH);
setEppInput("domain_delete_application_landrush.xml");
thrown.expect(SunriseApplicationCannotBeDeletedInLandrushException.class);
persistResource(newDomainApplication("example.tld")
.asBuilder()
.setRepoId("1-TLD")
.setPhase(LaunchPhase.SUNRISE)
.build());
thrown.expect(SunriseApplicationCannotBeDeletedInLandrushException.class);
runFlow();
}
@ -222,45 +222,45 @@ public class DomainApplicationDeleteFlowTest
@Test
public void testFailure_mismatchedPhase() throws Exception {
thrown.expect(LaunchPhaseMismatchException.class);
setEppInput("domain_delete_application_landrush.xml");
persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(LaunchPhaseMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongExtension() throws Exception {
thrown.expect(UnimplementedExtensionException.class);
setEppInput("domain_delete_application_wrong_extension.xml");
persistActiveDomainApplication("example.tld");
thrown.expect(UnimplementedExtensionException.class);
runFlow();
}
@Test
public void testFailure_predelegation() throws Exception {
thrown.expect(BadCommandForRegistryPhaseException.class);
createTld("tld", TldState.PREDELEGATION);
persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
}
@Test
public void testFailure_quietPeriod() throws Exception {
thrown.expect(BadCommandForRegistryPhaseException.class);
createTld("tld", TldState.QUIET_PERIOD);
persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
}
@Test
public void testFailure_generalAvailability() throws Exception {
thrown.expect(BadCommandForRegistryPhaseException.class);
createTld("tld", TldState.GENERAL_AVAILABILITY);
persistResource(
newDomainApplication("example.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(BadCommandForRegistryPhaseException.class);
runFlow();
}
@ -296,9 +296,9 @@ public class DomainApplicationDeleteFlowTest
@Test
public void testFailure_applicationIdForDifferentDomain() throws Exception {
thrown.expect(ApplicationDomainNameMismatchException.class);
persistResource(
newDomainApplication("invalid.tld").asBuilder().setRepoId("1-TLD").build());
thrown.expect(ApplicationDomainNameMismatchException.class);
runFlow();
}
}

View file

@ -268,54 +268,54 @@ public class DomainApplicationInfoFlowTest
@Test
public void testFailure_existedButWasDeleted() throws Exception {
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistResource(new DomainApplication.Builder()
.setRepoId("123-COM")
.setFullyQualifiedDomainName("timber.com")
.setDeletionTime(clock.nowUtc().minusDays(1))
.setRegistrant(Key.create(persistActiveContact("jd1234")))
.build());
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
}
@Test
public void testFailure_unauthorized() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
persistResource(
AppEngineRule.makeRegistrar1().asBuilder().setClientId("ClientZ").build());
sessionMetadata.setClientId("ClientZ");
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
thrown.expect(ResourceNotOwnedException.class);
runFlow();
}
@Test
public void testFailure_applicationIdForDifferentDomain() throws Exception {
thrown.expect(ApplicationDomainNameMismatchException.class);
persistResource(new DomainApplication.Builder()
.setRepoId("123-TLD")
.setFullyQualifiedDomainName("invalid.tld")
.setRegistrant(Key.create(persistActiveContact("jd1234")))
.setPhase(LaunchPhase.SUNRUSH)
.build());
thrown.expect(ApplicationDomainNameMismatchException.class);
runFlow();
}
@Test
public void testFailure_noApplicationId() throws Exception {
thrown.expect(MissingApplicationIdException.class);
setEppInput("domain_info_sunrise_no_application_id.xml");
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
thrown.expect(MissingApplicationIdException.class);
runFlow();
}
@Test
public void testFailure_mismatchedLaunchPhase() throws Exception {
thrown.expect(ApplicationLaunchPhaseMismatchException.class);
persistTestEntities(HostsState.NO_HOSTS_EXIST, MarksState.NO_MARKS_EXIST);
application = persistResource(
application.asBuilder().setPhase(LaunchPhase.SUNRISE).build());
thrown.expect(ApplicationLaunchPhaseMismatchException.class);
runFlow();
}
}

View file

@ -266,12 +266,12 @@ public class DomainCheckFlowTest
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
DatastoreHelper.persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
}
@ -625,156 +625,156 @@ public class DomainCheckFlowTest
@Test
public void testFeeExtension_wrongCurrency_v06() throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
setEppInput("domain_check_fee_euro_v06.xml");
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
}
@Test
public void testFeeExtension_wrongCurrency_v11() throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
setEppInput("domain_check_fee_euro_v11.xml");
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
}
@Test
public void testFeeExtension_wrongCurrency_v12() throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
setEppInput("domain_check_fee_euro_v12.xml");
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
}
@Test
public void testFeeExtension_periodNotInYears_v06() throws Exception {
thrown.expect(BadPeriodUnitException.class);
setEppInput("domain_check_fee_bad_period_v06.xml");
thrown.expect(BadPeriodUnitException.class);
runFlow();
}
@Test
public void testFeeExtension_periodNotInYears_v11() throws Exception {
thrown.expect(BadPeriodUnitException.class);
setEppInput("domain_check_fee_bad_period_v11.xml");
thrown.expect(BadPeriodUnitException.class);
runFlow();
}
@Test
public void testFeeExtension_periodNotInYears_v12() throws Exception {
thrown.expect(BadPeriodUnitException.class);
setEppInput("domain_check_fee_bad_period_v12.xml");
thrown.expect(BadPeriodUnitException.class);
runFlow();
}
@Test
public void testFeeExtension_commandWithPhase_v06() throws Exception {
thrown.expect(FeeChecksDontSupportPhasesException.class);
setEppInput("domain_check_fee_command_phase_v06.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
}
@Test
public void testFeeExtension_commandWithPhase_v11() throws Exception {
thrown.expect(FeeChecksDontSupportPhasesException.class);
setEppInput("domain_check_fee_command_phase_v11.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
}
@Test
public void testFeeExtension_commandWithPhase_v12() throws Exception {
thrown.expect(FeeChecksDontSupportPhasesException.class);
setEppInput("domain_check_fee_command_phase_v12.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
}
@Test
public void testFeeExtension_commandSubphase_v06() throws Exception {
thrown.expect(FeeChecksDontSupportPhasesException.class);
setEppInput("domain_check_fee_command_subphase_v06.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
}
@Test
public void testFeeExtension_commandSubphase_v11() throws Exception {
thrown.expect(FeeChecksDontSupportPhasesException.class);
setEppInput("domain_check_fee_command_subphase_v11.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
}
@Test
public void testFeeExtension_commandSubphase_v12() throws Exception {
thrown.expect(FeeChecksDontSupportPhasesException.class);
setEppInput("domain_check_fee_command_subphase_v12.xml");
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
}
// This test is only relevant for v06, since domain names are not specified in v11 or v12.
@Test
public void testFeeExtension_feeCheckNotInAvailabilityCheck() throws Exception {
thrown.expect(OnlyCheckedNamesCanBeFeeCheckedException.class);
setEppInput("domain_check_fee_not_in_avail.xml");
thrown.expect(OnlyCheckedNamesCanBeFeeCheckedException.class);
runFlow();
}
@Test
public void testFeeExtension_multiyearRestore_v06() throws Exception {
thrown.expect(RestoresAreAlwaysForOneYearException.class);
setEppInput("domain_check_fee_multiyear_restore_v06.xml");
thrown.expect(RestoresAreAlwaysForOneYearException.class);
runFlow();
}
@Test
public void testFeeExtension_multiyearRestore_v11() throws Exception {
thrown.expect(RestoresAreAlwaysForOneYearException.class);
setEppInput("domain_check_fee_multiyear_restore_v11.xml");
thrown.expect(RestoresAreAlwaysForOneYearException.class);
runFlow();
}
@Test
public void testFeeExtension_multiyearRestore_v12() throws Exception {
thrown.expect(RestoresAreAlwaysForOneYearException.class);
setEppInput("domain_check_fee_multiyear_restore_v12.xml");
thrown.expect(RestoresAreAlwaysForOneYearException.class);
runFlow();
}
@Test
public void testFeeExtension_unknownCommand_v06() throws Exception {
thrown.expect(UnknownFeeCommandException.class);
setEppInput("domain_check_fee_unknown_command_v06.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
}
@Test
public void testFeeExtension_unknownCommand_v11() throws Exception {
thrown.expect(UnknownFeeCommandException.class);
setEppInput("domain_check_fee_unknown_command_v11.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
}
@Test
public void testFeeExtension_unknownCommand_v12() throws Exception {
thrown.expect(UnknownFeeCommandException.class);
setEppInput("domain_check_fee_unknown_command_v12.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
}
@Test
public void testFeeExtension_invalidCommand_v06() throws Exception {
thrown.expect(UnknownFeeCommandException.class);
setEppInput("domain_check_fee_invalid_command_v06.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
}
@Test
public void testFeeExtension_invalidCommand_v11() throws Exception {
thrown.expect(UnknownFeeCommandException.class);
setEppInput("domain_check_fee_invalid_command_v11.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
}
@Test
public void testFeeExtension_invalidCommand_v12() throws Exception {
thrown.expect(UnknownFeeCommandException.class);
setEppInput("domain_check_fee_invalid_command_v12.xml");
thrown.expect(UnknownFeeCommandException.class);
runFlow();
}

View file

@ -621,16 +621,15 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
runFlow();
}
@Test
public void testFailure_hasSubordinateHosts() throws Exception {
thrown.expect(DomainToDeleteHasHostsException.class);
DomainResource domain = persistActiveDomain(getUniqueIdFromCommand());
HostResource subordinateHost = persistResource(
newHostResource("ns1." + getUniqueIdFromCommand()).asBuilder()
@ -639,26 +638,27 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
domain = persistResource(domain.asBuilder()
.addSubordinateHost(subordinateHost.getFullyQualifiedHostName())
.build());
thrown.expect(DomainToDeleteHasHostsException.class);
runFlow();
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
sessionMetadata.setClientId("NewRegistrar");
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
setupSuccessfulTest();
persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
}
@ -673,28 +673,28 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
@Test
public void testFailure_clientDeleteProhibited() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.addStatusValue(StatusValue.CLIENT_DELETE_PROHIBITED)
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@Test
public void testFailure_serverDeleteProhibited() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.addStatusValue(StatusValue.SERVER_DELETE_PROHIBITED)
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@Test
public void testFailure_pendingDelete() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@ -718,9 +718,9 @@ public class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow,
@Test
public void testFailure_metadataNotFromTool() throws Exception {
thrown.expect(OnlyToolCanPassMetadataException.class);
setEppInput("domain_delete_metadata.xml");
persistResource(newDomainResource(getUniqueIdFromCommand()));
thrown.expect(OnlyToolCanPassMetadataException.class);
runFlow();
}

View file

@ -382,18 +382,17 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
@Test
public void testFailure_existedButWasDeleted() throws Exception {
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistResource(newDomainResource("example.tld").asBuilder()
.setDeletionTime(clock.nowUtc().minusDays(1))
.build());
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
runFlow();
}
@Test
public void testFailure_differentRegistrarWrongAuthInfo() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
persistTestEntities(false);
// Change the password of the domain so that it does not match the file.
persistResource(domain.asBuilder()
@ -401,24 +400,24 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
.build());
sessionMetadata.setClientId("ClientZ");
setEppInput("domain_info_with_auth.xml");
thrown.expect(BadAuthInfoForResourceException.class);
runFlow();
}
@Test
public void testFailure_wrongAuthInfo() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
persistTestEntities(false);
// Change the password of the domain so that it does not match the file.
persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("diffpw")))
.build());
setEppInput("domain_info_with_auth.xml");
thrown.expect(BadAuthInfoForResourceException.class);
runFlow();
}
@Test
public void testFailure_differentRegistrarWrongRegistrantAuthInfo() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
persistTestEntities(false);
// Change the password of the registrant so that it does not match the file.
registrant = persistResource(
@ -429,12 +428,12 @@ 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();
}
@Test
public void testFailure_wrongRegistrantAuthInfo() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
persistTestEntities(false);
// Change the password of the registrant so that it does not match the file.
registrant = persistResource(
@ -444,12 +443,12 @@ 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();
}
@Test
public void testFailure_differentRegistrarWrongContactAuthInfo() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
persistTestEntities(false);
// Change the password of the contact so that it does not match the file.
contact = persistResource(
@ -460,12 +459,12 @@ 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();
}
@Test
public void testFailure_wrongContactAuthInfo() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
persistTestEntities(false);
// Change the password of the contact so that it does not match the file.
contact = persistResource(
@ -475,29 +474,30 @@ 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();
}
@Test
public void testFailure_differentRegistrarUnrelatedContactAuthInfo() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
persistTestEntities(false);
ContactResource unrelatedContact = persistActiveContact("foo1234");
sessionMetadata.setClientId("ClientZ");
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();
}
@Test
public void testFailure_unrelatedContactAuthInfo() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
persistTestEntities(false);
ContactResource unrelatedContact = persistActiveContact("foo1234");
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();
}
@ -575,45 +575,45 @@ public class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, Dom
/** Test setting the currency explicitly to a wrong value. */
@Test
public void testFeeExtension_wrongCurrency() throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
setEppInput("domain_info_fee_create_euro.xml");
persistTestEntities(false);
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
}
/** Test requesting a period that isn't in years. */
@Test
public void testFeeExtension_periodNotInYears() throws Exception {
thrown.expect(BadPeriodUnitException.class);
setEppInput("domain_info_fee_bad_period.xml");
persistTestEntities(false);
thrown.expect(BadPeriodUnitException.class);
runFlow();
}
/** Test a command that specifies a phase. */
@Test
public void testFeeExtension_commandPhase() throws Exception {
thrown.expect(FeeChecksDontSupportPhasesException.class);
setEppInput("domain_info_fee_command_phase.xml");
persistTestEntities(false);
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
}
/** Test a command that specifies a subphase. */
@Test
public void testFeeExtension_commandSubphase() throws Exception {
thrown.expect(FeeChecksDontSupportPhasesException.class);
setEppInput("domain_info_fee_command_subphase.xml");
persistTestEntities(false);
thrown.expect(FeeChecksDontSupportPhasesException.class);
runFlow();
}
/** Test a restore for more than one year. */
@Test
public void testFeeExtension_multiyearRestore() throws Exception {
thrown.expect(RestoresAreAlwaysForOneYearException.class);
setEppInput("domain_info_fee_multiyear_restore.xml");
persistTestEntities(false);
thrown.expect(RestoresAreAlwaysForOneYearException.class);
runFlow();
}

View file

@ -259,73 +259,73 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
@Test
public void testFailure_refundableFee_v06() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_refundable.xml", FEE_06_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_refundableFee_v11() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_refundable.xml", FEE_11_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_refundableFee_v12() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_refundable.xml", FEE_12_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_gracePeriodFee_v06() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_grace_period.xml", FEE_06_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_gracePeriodFee_v11() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_grace_period.xml", FEE_11_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_gracePeriodFee_v12() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_grace_period.xml", FEE_12_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_appliedFee_v06() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_applied.xml", FEE_06_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_appliedFee_v11() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_applied.xml", FEE_11_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_appliedFee_v12() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_renew_fee_applied.xml", FEE_12_MAP);
persistDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@ -388,30 +388,29 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
runFlow();
}
@Test
public void testFailure_clientRenewProhibited() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistDomain(StatusValue.CLIENT_RENEW_PROHIBITED);
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@Test
public void testFailure_serverRenewProhibited() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistDomain(StatusValue.SERVER_RENEW_PROHIBITED);
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@Test
public void testFailure_wrongFeeAmount_v06() throws Exception {
thrown.expect(FeesMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_06_MAP);
persistResource(
Registry.get("tld")
@ -419,12 +418,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build());
persistDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongFeeAmount_v11() throws Exception {
thrown.expect(FeesMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_11_MAP);
persistResource(
Registry.get("tld")
@ -432,12 +431,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build());
persistDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongFeeAmount_v12() throws Exception {
thrown.expect(FeesMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_12_MAP);
persistResource(
Registry.get("tld")
@ -445,12 +444,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build());
persistDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongCurrency_v06() throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_06_MAP);
persistResource(
Registry.get("tld")
@ -463,12 +462,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongCurrency_v11() throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_11_MAP);
persistResource(
Registry.get("tld")
@ -481,12 +480,12 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongCurrency_v12() throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
setEppInput("domain_renew_fee.xml", FEE_12_MAP);
persistResource(
Registry.get("tld")
@ -499,99 +498,100 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
persistDomain();
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
}
@Test
public void testFailure_feeGivenInWrongScale_v06() throws Exception {
thrown.expect(CurrencyValueScaleException.class);
setEppInput("domain_renew_fee_bad_scale.xml", FEE_06_MAP);
persistDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
}
@Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception {
thrown.expect(CurrencyValueScaleException.class);
setEppInput("domain_renew_fee_bad_scale.xml", FEE_11_MAP);
persistDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
}
@Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception {
thrown.expect(CurrencyValueScaleException.class);
setEppInput("domain_renew_fee_bad_scale.xml", FEE_12_MAP);
persistDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
}
@Test
public void testFailure_pendingTransfer() throws Exception {
thrown.expect(DomainHasPendingTransferException.class);
persistDomain();
persistWithPendingTransfer(reloadResourceByForeignKey()
.asBuilder()
.setRegistrationExpirationTime(DateTime.parse("2001-09-08T22:00:00.0Z"))
.build());
thrown.expect(DomainHasPendingTransferException.class);
runFlow();
}
@Test
public void testFailure_periodInMonths() throws Exception {
thrown.expect(BadPeriodUnitException.class);
setEppInput("domain_renew_months.xml");
persistDomain();
thrown.expect(BadPeriodUnitException.class);
runFlow();
}
@Test
public void testFailure_max10Years() throws Exception {
thrown.expect(ExceedsMaxRegistrationYearsException.class);
setEppInput("domain_renew_11_years.xml");
persistDomain();
thrown.expect(ExceedsMaxRegistrationYearsException.class);
runFlow();
}
@Test
public void testFailure_pendingDelete() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setRegistrationExpirationTime(expirationTime)
.setDeletionTime(clock.nowUtc().plusDays(1))
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@Test
public void testFailure_curExpDateMustMatch() throws Exception {
thrown.expect(IncorrectCurrentExpirationDateException.class);
persistDomain();
// Note expiration time is off by one day.
persistResource(reloadResourceByForeignKey().asBuilder()
.setRegistrationExpirationTime(DateTime.parse("2000-04-04T22:00:00.0Z"))
.build());
thrown.expect(IncorrectCurrentExpirationDateException.class);
runFlow();
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
sessionMetadata.setClientId("NewRegistrar");
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
persistDomain();
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
}
@ -605,11 +605,11 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
@Test
public void testFailure_feeNotProvidedOnPremiumName() throws Exception {
thrown.expect(FeesRequiredForPremiumNameException.class);
createTld("example");
persistResource(Registry.get("example").asBuilder().setPremiumPriceAckRequired(true).build());
setEppInput("domain_renew_premium.xml");
persistDomain();
thrown.expect(FeesRequiredForPremiumNameException.class);
runFlow();
}

View file

@ -233,73 +233,73 @@ public class DomainRestoreRequestFlowTest extends
@Test
public void testFailure_refundableFee_v06() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_06_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_refundableFee_v11() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_11_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_refundableFee_v12() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_update_restore_request_fee_refundable.xml", FEE_12_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_gracePeriodFee_v06() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_06_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_gracePeriodFee_v11() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_11_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_gracePeriodFee_v12() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_update_restore_request_fee_grace_period.xml", FEE_12_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_appliedFee_v06() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_06_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_appliedFee_v11() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_11_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@Test
public void testFailure_appliedFee_v12() throws Exception {
thrown.expect(UnsupportedFeeAttributeException.class);
setEppInput("domain_update_restore_request_fee_applied.xml", FEE_12_MAP);
persistPendingDeleteDomain();
thrown.expect(UnsupportedFeeAttributeException.class);
runFlow();
}
@ -351,36 +351,35 @@ public class DomainRestoreRequestFlowTest extends
@Test
public void testFailure_wrongFeeAmount_v06() throws Exception {
thrown.expect(FeesMismatchException.class);
setEppInput("domain_update_restore_request_fee.xml", FEE_06_MAP);
persistPendingDeleteDomain();
persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
thrown.expect(FeesMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongFeeAmount_v11() throws Exception {
thrown.expect(FeesMismatchException.class);
setEppInput("domain_update_restore_request_fee.xml", FEE_11_MAP);
persistPendingDeleteDomain();
persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
thrown.expect(FeesMismatchException.class);
runFlow();
}
@Test
public void testFailure_wrongFeeAmount_v12() throws Exception {
thrown.expect(FeesMismatchException.class);
setEppInput("domain_update_restore_request_fee.xml", FEE_12_MAP);
persistPendingDeleteDomain();
persistResource(
Registry.get("tld").asBuilder().setRestoreBillingCost(Money.of(USD, 100)).build());
thrown.expect(FeesMismatchException.class);
runFlow();
}
private void runWrongCurrencyTest(Map<String, String> substitutions) throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
setEppInput("domain_update_restore_request_fee.xml", substitutions);
persistPendingDeleteDomain();
persistResource(
@ -393,6 +392,7 @@ public class DomainRestoreRequestFlowTest extends
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
thrown.expect(CurrencyUnitMismatchException.class);
runFlow();
}
@ -413,127 +413,126 @@ public class DomainRestoreRequestFlowTest extends
@Test
public void testFailure_feeGivenInWrongScale_v06() throws Exception {
thrown.expect(CurrencyValueScaleException.class);
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_06_MAP);
persistPendingDeleteDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
}
@Test
public void testFailure_feeGivenInWrongScale_v11() throws Exception {
thrown.expect(CurrencyValueScaleException.class);
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_11_MAP);
persistPendingDeleteDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
}
@Test
public void testFailure_feeGivenInWrongScale_v12() throws Exception {
thrown.expect(CurrencyValueScaleException.class);
setEppInput("domain_update_restore_request_fee_bad_scale.xml", FEE_12_MAP);
persistPendingDeleteDomain();
thrown.expect(CurrencyValueScaleException.class);
runFlow();
}
@Test
public void testFailure_notInRedemptionPeriod() throws Exception {
thrown.expect(DomainNotEligibleForRestoreException.class);
persistResource(newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setDeletionTime(clock.nowUtc().plusDays(4))
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.build());
thrown.expect(DomainNotEligibleForRestoreException.class);
runFlow();
}
@Test
public void testFailure_notDeleted() throws Exception {
thrown.expect(DomainNotEligibleForRestoreException.class);
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(DomainNotEligibleForRestoreException.class);
runFlow();
}
@Test
public void testFailure_fullyDeleted() throws Exception {
thrown.expect(ResourceDoesNotExistException.class);
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(ResourceDoesNotExistException.class);
runFlow();
}
@Test
public void testFailure_withChange() throws Exception {
thrown.expect(RestoreCommandIncludesChangesException.class);
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_change.xml");
thrown.expect(RestoreCommandIncludesChangesException.class);
runFlow();
}
@Test
public void testFailure_withAdd() throws Exception {
thrown.expect(RestoreCommandIncludesChangesException.class);
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_add.xml");
thrown.expect(RestoreCommandIncludesChangesException.class);
runFlow();
}
@Test
public void testFailure_withRemove() throws Exception {
thrown.expect(RestoreCommandIncludesChangesException.class);
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_remove.xml");
thrown.expect(RestoreCommandIncludesChangesException.class);
runFlow();
}
@Test
public void testFailure_withSecDnsExtension() throws Exception {
thrown.expect(UnimplementedExtensionException.class);
persistPendingDeleteDomain();
setEppInput("domain_update_restore_request_with_secdns.xml");
thrown.expect(UnimplementedExtensionException.class);
runFlow();
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
sessionMetadata.setClientId("NewRegistrar");
persistPendingDeleteDomain();
thrown.expect(ResourceNotOwnedException.class);
runFlow();
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
persistPendingDeleteDomain();
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
}
@Test
public void testSuccess_superuserUnauthorizedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
sessionMetadata.setClientId("NewRegistrar");
persistPendingDeleteDomain();
thrown.expect(ResourceNotOwnedException.class);
runFlowAssertResponse(readFile("domain_update_response.xml"));
}
@Test
public void testFailure_premiumBlocked() throws Exception {
thrown.expect(PremiumNameBlockedException.class);
createTld("example");
setEppInput("domain_update_restore_request_premium.xml");
persistPendingDeleteDomain();
// Modify the Registrar to block premium names.
persistResource(
Registrar.loadByClientId("TheRegistrar").asBuilder().setBlockPremiumNames(true).build());
thrown.expect(PremiumNameBlockedException.class);
runFlow();
}
@Test
public void testFailure_reservedBlocked() throws Exception {
thrown.expect(DomainReservedException.class);
createTld("tld");
persistResource(
Registry.get("tld")
@ -541,15 +540,16 @@ public class DomainRestoreRequestFlowTest extends
.setReservedLists(persistReservedList("tld-reserved", "example,FULLY_BLOCKED"))
.build());
persistPendingDeleteDomain();
thrown.expect(DomainReservedException.class);
runFlow();
}
@Test
public void testFailure_feeNotProvidedOnPremiumName() throws Exception {
thrown.expect(FeesRequiredForPremiumNameException.class);
createTld("example");
setEppInput("domain_update_restore_request_premium.xml");
persistPendingDeleteDomain();
thrown.expect(FeesRequiredForPremiumNameException.class);
runFlow();
}

View file

@ -379,106 +379,106 @@ public class DomainTransferApproveFlowTest
@Test
public void testFailure_badContactPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_approve_contact_authinfo.xml");
}
@Test
public void testFailure_badDomainPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the domain's password so it does not match the password in the file.
domain = persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_approve_domain_authinfo.xml");
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
}
@Test
public void testFailure_clientApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
}
@Test
public void testFailure_clientRejected() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
}
@Test
public void testFailure_clientCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
}
@Test
public void testFailure_serverApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
}
@Test
public void testFailure_serverCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_approve.xml");
}
@Test
public void testFailure_gainingClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("domain_transfer_approve.xml");
}
@Test
public void testFailure_unrelatedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
setClientIdForFlow("ClientZ");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("domain_transfer_approve.xml");
}
@Test
public void testFailure_deletedDomain() throws Exception {
thrown.expect(ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
doFailingTest("domain_transfer_approve.xml");
}
@Test
public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain);
thrown.expect(ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
deleteResource(domain);
doFailingTest("domain_transfer_approve.xml");
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
thrown.expect(NotAuthorizedForTldException.class);
doSuccessfulTest("tld", "domain_transfer_approve.xml", "domain_transfer_approve_response.xml");
}

View file

@ -192,108 +192,108 @@ public class DomainTransferCancelFlowTest
@Test
public void testFailure_badContactPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_cancel_contact_authinfo.xml");
}
@Test
public void testFailure_badDomainPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the domain's password so it does not match the password in the file.
domain = persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_cancel_domain_authinfo.xml");
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
}
@Test
public void testFailure_clientApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
}
@Test
public void testFailure_clientRejected() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
}
@Test
public void testFailure_clientCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
}
@Test
public void testFailure_serverApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
}
@Test
public void testFailure_serverCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_cancel.xml");
}
@Test
public void testFailure_sponsoringClient() throws Exception {
thrown.expect(NotTransferInitiatorException.class);
setClientIdForFlow("TheRegistrar");
thrown.expect(NotTransferInitiatorException.class);
doFailingTest("domain_transfer_cancel.xml");
}
@Test
public void testFailure_unrelatedClient() throws Exception {
thrown.expect(NotTransferInitiatorException.class);
setClientIdForFlow("ClientZ");
thrown.expect(NotTransferInitiatorException.class);
doFailingTest("domain_transfer_cancel.xml");
}
@Test
public void testFailure_deletedDomain() throws Exception {
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
doFailingTest("domain_transfer_cancel.xml");
}
@Test
public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain);
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
deleteResource(domain);
doFailingTest("domain_transfer_cancel.xml");
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
persistResource(
Registrar.loadByClientId("NewRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
thrown.expect(NotAuthorizedForTldException.class);
doSuccessfulTest("domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml");
}

View file

@ -170,55 +170,55 @@ public class DomainTransferQueryFlowTest
@Test
public void testFailure_badContactPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_query_contact_authinfo.xml");
}
@Test
public void testFailure_badDomainPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the domain's password so it does not match the password in the file.
domain = persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_query_domain_authinfo.xml");
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
thrown.expect(NoTransferHistoryToQueryException.class);
changeTransferStatus(null);
thrown.expect(NoTransferHistoryToQueryException.class);
doFailingTest("domain_transfer_query.xml");
}
@Test
public void testFailure_unrelatedClient() throws Exception {
thrown.expect(NotAuthorizedToViewTransferException.class);
setClientIdForFlow("ClientZ");
thrown.expect(NotAuthorizedToViewTransferException.class);
doFailingTest("domain_transfer_query.xml");
}
@Test
public void testFailure_deletedDomain() throws Exception {
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
doFailingTest("domain_transfer_query.xml");
}
@Test
public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain);
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
deleteResource(domain);
doFailingTest("domain_transfer_query.xml");
}
}

View file

@ -153,109 +153,109 @@ public class DomainTransferRejectFlowTest
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
thrown.expect(NotAuthorizedForTldException.class);
doSuccessfulTest("domain_transfer_reject.xml", "domain_transfer_reject_response.xml");
}
@Test
public void testFailure_badContactPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_reject_contact_authinfo.xml");
}
@Test
public void testFailure_badDomainPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the domain's password so it does not match the password in the file.
domain = persistResource(
domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_reject_domain_authinfo.xml");
}
@Test
public void testFailure_neverBeenTransferred() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(null);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_clientApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_clientRejected() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_clientCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_serverApproved() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_APPROVED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_serverCancelled() throws Exception {
thrown.expect(NotPendingTransferException.class);
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
thrown.expect(NotPendingTransferException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_gainingClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
setClientIdForFlow("NewRegistrar");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_unrelatedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
setClientIdForFlow("ClientZ");
thrown.expect(ResourceNotOwnedException.class);
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_deletedDomain() throws Exception {
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
doFailingTest("domain_transfer_reject.xml");
}
@Test
public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain);
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
deleteResource(domain);
doFailingTest("domain_transfer_reject.xml");
}

View file

@ -493,12 +493,12 @@ public class DomainTransferRequestFlowTest
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
persistResource(
Registrar.loadByClientId("NewRegistrar")
.asBuilder()
.setAllowedTlds(ImmutableSet.<String>of())
.build());
thrown.expect(NotAuthorizedForTldException.class);
doSuccessfulTest("domain_transfer_request.xml", "domain_transfer_request_response.xml");
}
@ -548,7 +548,6 @@ public class DomainTransferRequestFlowTest
}
private void runWrongCurrencyTest(Map<String, String> substitutions) throws Exception {
thrown.expect(CurrencyUnitMismatchException.class);
persistResource(
Registry.get("tld")
.asBuilder()
@ -559,6 +558,7 @@ public class DomainTransferRequestFlowTest
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
.build());
thrown.expect(CurrencyUnitMismatchException.class);
doFailingTest("domain_transfer_request_fee.xml", substitutions);
}
@ -597,12 +597,12 @@ public class DomainTransferRequestFlowTest
private void runWrongFeeAmountTest(Map<String, String> substitutions) throws Exception {
thrown.expect(FeesMismatchException.class);
persistResource(
Registry.get("tld")
.asBuilder()
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 20)))
.build());
thrown.expect(FeesMismatchException.class);
doFailingTest("domain_transfer_request_fee.xml", substitutions);
}
@ -623,18 +623,18 @@ public class DomainTransferRequestFlowTest
@Test
public void testFailure_premiumBlocked() throws Exception {
thrown.expect(PremiumNameBlockedException.class);
setupDomain("rich", "example");
// Modify the Registrar to block premium names.
persistResource(
Registrar.loadByClientId("NewRegistrar").asBuilder().setBlockPremiumNames(true).build());
thrown.expect(PremiumNameBlockedException.class);
doFailingTest("domain_transfer_request_premium.xml");
}
@Test
public void testFailure_feeNotProvidedOnPremiumName() throws Exception {
thrown.expect(FeesRequiredForPremiumNameException.class);
setupDomain("rich", "example");
thrown.expect(FeesRequiredForPremiumNameException.class);
doFailingTest("domain_transfer_request_premium.xml");
}
@ -646,21 +646,21 @@ public class DomainTransferRequestFlowTest
@Test
public void testFailure_badContactPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the contact's password so it does not match the password in the file.
contact = persistResource(
contact.asBuilder()
.setAuthInfo(ContactAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_request.xml");
}
@Test
public void testFailure_badContactRepoId() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Set the contact to a different ROID, but don't persist it; this is just so the substitution
// code above will write the wrong ROID into the file.
contact = contact.asBuilder().setRepoId("DEADBEEF_TLD-ROID").build();
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_request.xml");
}
@ -696,40 +696,40 @@ public class DomainTransferRequestFlowTest
@Test
public void testFailure_pending() throws Exception {
thrown.expect(AlreadyPendingTransferException.class);
domain = persistResource(domain.asBuilder()
.setTransferData(domain.getTransferData().asBuilder()
.setTransferStatus(TransferStatus.PENDING)
.setPendingTransferExpirationTime(clock.nowUtc().plusDays(1))
.build())
.build());
thrown.expect(AlreadyPendingTransferException.class);
doFailingTest("domain_transfer_request.xml");
}
@Test
public void testFailure_badDomainPassword() throws Exception {
thrown.expect(BadAuthInfoForResourceException.class);
// Change the domain's password so it does not match the password in the file.
domain = persistResource(domain.asBuilder()
.setAuthInfo(DomainAuthInfo.create(PasswordAuth.create("badpassword")))
.build());
thrown.expect(BadAuthInfoForResourceException.class);
doFailingTest("domain_transfer_request_domain_authinfo.xml");
}
@Test
public void testFailure_sponsoringClient() throws Exception {
thrown.expect(ObjectAlreadySponsoredException.class);
setClientIdForFlow("TheRegistrar");
thrown.expect(ObjectAlreadySponsoredException.class);
doFailingTest("domain_transfer_request.xml");
}
@Test
public void testFailure_deletedDomain() throws Exception {
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
doFailingTest("domain_transfer_request.xml");
}
@ -744,10 +744,10 @@ public class DomainTransferRequestFlowTest
@Test
public void testFailure_nonexistentDomain() throws Exception {
deleteResource(domain);
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
deleteResource(domain);
doFailingTest("domain_transfer_request.xml");
}
@ -759,9 +759,9 @@ public class DomainTransferRequestFlowTest
@Test
public void testFailure_pendingDelete() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
domain = persistResource(
domain.asBuilder().addStatusValue(StatusValue.PENDING_DELETE).build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
doFailingTest("domain_transfer_request.xml");
}

View file

@ -444,10 +444,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
@Test
public void testSuccess_metadataNotFromTool() throws Exception {
thrown.expect(OnlyToolCanPassMetadataException.class);
setEppInput("domain_update_metadata.xml");
persistReferencedEntities();
persistDomain();
thrown.expect(OnlyToolCanPassMetadataException.class);
runFlow();
}
@ -759,10 +759,10 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
private void doSecDnsFailingTest(Class<? extends Exception> expectedException, String xmlFilename)
throws Exception {
thrown.expect(expectedException);
setEppInput(xmlFilename);
persistReferencedEntities();
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(expectedException);
runFlow();
}
@ -793,7 +793,6 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
@Test
public void testFailure_secDnsTooManyDsRecords() throws Exception {
thrown.expect(TooManyDsRecordsException.class);
ImmutableSet.Builder<DelegationSignerData> builder = new ImmutableSet.Builder<>();
for (int i = 0; i < 8; ++i) {
builder.add(DelegationSignerData.create(i, 2, 3, new byte[]{0, 1, 2}));
@ -804,99 +803,99 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setDsData(builder.build())
.build());
thrown.expect(TooManyDsRecordsException.class);
runFlow();
}
@Test
public void testFailure_tooManyNameservers() throws Exception {
thrown.expect(TooManyNameserversException.class);
setEppInput("domain_update_add_nameserver.xml");
persistReferencedEntities();
persistDomain();
// Modify domain so it has 13 nameservers. We will then try to add one in the test.
modifyDomainToHave13Nameservers();
thrown.expect(TooManyNameserversException.class);
runFlow();
}
@Test
public void testFailure_wrongExtension() throws Exception {
thrown.expect(UnimplementedExtensionException.class);
setEppInput("domain_update_wrong_extension.xml");
persistReferencedEntities();
persistDomain();
thrown.expect(UnimplementedExtensionException.class);
runFlow();
}
@Test
public void testFailure_neverExisted() throws Exception {
persistReferencedEntities();
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistReferencedEntities();
runFlow();
}
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistReferencedEntities();
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistReferencedEntities();
persistDeletedDomain(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
runFlow();
}
@Test
public void testFailure_clientUpdateProhibited() throws Exception {
createTld("com");
thrown.expect(ResourceHasClientUpdateProhibitedException.class);
setEppInput("domain_update_authinfo.xml");
persistReferencedEntities();
persistResource(
newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
.build());
thrown.expect(ResourceHasClientUpdateProhibitedException.class);
runFlow();
}
@Test
public void testFailure_serverUpdateProhibited() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistReferencedEntities();
persistResource(
newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(StatusValue.SERVER_UPDATE_PROHIBITED))
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@Test
public void testFailure_missingHost() throws Exception {
thrown.expect(
LinkedResourcesDoNotExistException.class,
"(ns2.example.foo)");
persistActiveHost("ns1.example.foo");
persistActiveContact("sh8013");
persistActiveContact("mak21");
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(
LinkedResourcesDoNotExistException.class,
"(ns2.example.foo)");
runFlow();
}
@Test
public void testFailure_missingContact() throws Exception {
thrown.expect(
LinkedResourcesDoNotExistException.class,
"(sh8013)");
persistActiveHost("ns1.example.foo");
persistActiveHost("ns2.example.foo");
persistActiveContact("mak21");
persistActiveDomain(getUniqueIdFromCommand());
thrown.expect(
LinkedResourcesDoNotExistException.class,
"(sh8013)");
runFlow();
}
@Test
public void testFailure_addingDuplicateContact() throws Exception {
thrown.expect(DuplicateContactForRoleException.class);
persistReferencedEntities();
persistActiveContact("foo");
persistDomain();
@ -908,15 +907,16 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
DesignatedContact.create(Type.TECH, Key.create(
loadByForeignKey(ContactResource.class, "foo", clock.nowUtc())))))
.build());
thrown.expect(DuplicateContactForRoleException.class);
runFlow();
}
@Test
public void testFailure_clientProhibitedStatusValue() throws Exception {
thrown.expect(StatusNotClientSettableException.class);
setEppInput("domain_update_prohibited_status.xml");
persistReferencedEntities();
persistDomain();
thrown.expect(StatusNotClientSettableException.class);
runFlow();
}
@ -933,47 +933,46 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
@Test
public void testFailure_pendingDelete() throws Exception {
thrown.expect(ResourceStatusProhibitsOperationException.class);
persistReferencedEntities();
persistResource(
newDomainResource(getUniqueIdFromCommand()).asBuilder()
.setDeletionTime(clock.nowUtc().plusDays(1))
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
thrown.expect(ResourceStatusProhibitsOperationException.class);
runFlow();
}
@Test
public void testFailure_duplicateContactInCommand() throws Exception {
thrown.expect(DuplicateContactForRoleException.class);
setEppInput("domain_update_duplicate_contact.xml");
persistReferencedEntities();
persistDomain();
thrown.expect(DuplicateContactForRoleException.class);
runFlow();
}
@Test
public void testFailure_missingContactType() throws Exception {
// We need to test for missing type, but not for invalid - the schema enforces that for us.
thrown.expect(MissingContactTypeException.class);
setEppInput("domain_update_missing_contact_type.xml");
persistReferencedEntities();
persistDomain();
thrown.expect(MissingContactTypeException.class);
runFlow();
}
@Test
public void testFailure_unauthorizedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
sessionMetadata.setClientId("NewRegistrar");
persistReferencedEntities();
persistDomain();
thrown.expect(ResourceNotOwnedException.class);
runFlow();
}
@Test
public void testFailure_notAuthorizedForTld() throws Exception {
thrown.expect(NotAuthorizedForTldException.class);
persistResource(
Registrar.loadByClientId("TheRegistrar")
.asBuilder()
@ -981,6 +980,7 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.build());
persistReferencedEntities();
persistDomain();
thrown.expect(NotAuthorizedForTldException.class);
runFlow();
}
@ -996,7 +996,6 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
@Test
public void testFailure_sameNameserverAddedAndRemoved() throws Exception {
thrown.expect(AddRemoveSameValueEppException.class);
setEppInput("domain_update_add_remove_same_host.xml");
persistReferencedEntities();
persistResource(
@ -1004,12 +1003,12 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.setNameservers(ImmutableSet.of(Key.create(
loadByForeignKey(HostResource.class, "ns1.example.foo", clock.nowUtc()))))
.build());
thrown.expect(AddRemoveSameValueEppException.class);
runFlow();
}
@Test
public void testFailure_sameContactAddedAndRemoved() throws Exception {
thrown.expect(AddRemoveSameValueEppException.class);
setEppInput("domain_update_add_remove_same_contact.xml");
persistReferencedEntities();
persistResource(
@ -1019,12 +1018,12 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
Key.create(
loadByForeignKey(ContactResource.class, "sh8013", clock.nowUtc())))))
.build());
thrown.expect(AddRemoveSameValueEppException.class);
runFlow();
}
@Test
public void testFailure_removeAdmin() throws Exception {
thrown.expect(MissingAdminContactException.class);
setEppInput("domain_update_remove_admin.xml");
persistReferencedEntities();
persistResource(
@ -1033,12 +1032,12 @@ 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();
}
@Test
public void testFailure_removeTech() throws Exception {
thrown.expect(MissingTechnicalContactException.class);
setEppInput("domain_update_remove_tech.xml");
persistReferencedEntities();
persistResource(
@ -1047,14 +1046,12 @@ 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();
}
@Test
public void testFailure_addPendingDeleteContact() throws Exception {
thrown.expect(
LinkedResourceInPendingDeleteProhibitsOperationException.class,
"mak21");
persistReferencedEntities();
persistDomain();
persistActiveHost("ns1.example.foo");
@ -1064,14 +1061,14 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
clock.advanceOneMilli();
thrown.expect(
LinkedResourceInPendingDeleteProhibitsOperationException.class,
"mak21");
runFlow();
}
@Test
public void testFailure_addPendingDeleteHost() throws Exception {
thrown.expect(
LinkedResourceInPendingDeleteProhibitsOperationException.class,
"ns2.example.foo");
persistReferencedEntities();
persistDomain();
persistActiveHost("ns1.example.foo");
@ -1082,6 +1079,9 @@ public class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow,
.addStatusValue(StatusValue.PENDING_DELETE)
.build());
clock.advanceOneMilli();
thrown.expect(
LinkedResourceInPendingDeleteProhibitsOperationException.class,
"ns2.example.foo");
runFlow();
}

View file

@ -47,11 +47,11 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
private void doFailingStatusTest(StatusValue statusValue, Class<? extends Exception> exception)
throws Exception {
thrown.expect(exception);
persistResource(
newHostResource(getUniqueIdFromCommand()).asBuilder()
.setStatusValues(ImmutableSet.of(statusValue))
.build());
thrown.expect(exception);
runFlow();
}
@ -87,10 +87,10 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistDeletedHost(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistDeletedHost(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
runFlow();
}
@ -114,9 +114,9 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
@Test
public void testFailure_unauthorizedClient() throws Exception {
thrown.expect(ResourceNotOwnedException.class);
sessionMetadata.setClientId("NewRegistrar");
persistActiveHost(getUniqueIdFromCommand());
thrown.expect(ResourceNotOwnedException.class);
runFlow();
}

View file

@ -152,10 +152,10 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
@Test
public void testFailure_existedButWasDeleted() throws Exception {
persistHostResource(false);
thrown.expect(
ResourceDoesNotExistException.class,
String.format("(%s)", getUniqueIdFromCommand()));
persistHostResource(false);
runFlow();
}
}

View file

@ -150,48 +150,47 @@ public class PollAckFlowTest extends FlowTestCase<PollAckFlow> {
@Test
public void testFailure_noSuchMessage() throws Exception {
assertTransactionalFlow(true);
thrown.expect(
MessageDoesNotExistException.class,
String.format("(1-3-EXAMPLE-4-%d)", MESSAGE_ID));
assertTransactionalFlow(true);
runFlow();
}
@Test
public void testFailure_invalidId_wrongNumberOfComponents() throws Exception {
thrown.expect(InvalidMessageIdException.class);
setEppInput("poll_ack_invalid_id.xml");
assertTransactionalFlow(true);
thrown.expect(InvalidMessageIdException.class);
runFlow();
}
@Test
public void testFailure_invalidId_stringInsteadOfNumeric() throws Exception {
thrown.expect(InvalidMessageIdException.class);
setEppInput("poll_ack_invalid_string_id.xml");
assertTransactionalFlow(true);
thrown.expect(InvalidMessageIdException.class);
runFlow();
}
@Test
public void testFailure_invalidEppResourceClassId() throws Exception {
thrown.expect(InvalidMessageIdException.class);
setEppInput("poll_ack_invalid_eppresource_id.xml");
assertTransactionalFlow(true);
thrown.expect(InvalidMessageIdException.class);
runFlow();
}
@Test
public void testFailure_missingId() throws Exception {
thrown.expect(MissingMessageIdException.class);
setEppInput("poll_ack_missing_id.xml");
assertTransactionalFlow(true);
thrown.expect(MissingMessageIdException.class);
runFlow();
}
@Test
public void testFailure_differentRegistrar() throws Exception {
thrown.expect(NotAuthorizedToAckMessageException.class);
persistResource(
new PollMessage.OneTime.Builder()
.setId(MESSAGE_ID)
@ -201,14 +200,12 @@ public class PollAckFlowTest extends FlowTestCase<PollAckFlow> {
.setParent(createHistoryEntryForEppResource(domain))
.build());
assertTransactionalFlow(true);
thrown.expect(NotAuthorizedToAckMessageException.class);
runFlow();
}
@Test
public void testFailure_messageInFuture() throws Exception {
thrown.expect(
MessageDoesNotExistException.class,
String.format("(1-3-EXAMPLE-4-%d)", MESSAGE_ID));
persistResource(
new PollMessage.OneTime.Builder()
.setId(MESSAGE_ID)
@ -218,6 +215,9 @@ public class PollAckFlowTest extends FlowTestCase<PollAckFlow> {
.setParent(createHistoryEntryForEppResource(domain))
.build());
assertTransactionalFlow(true);
thrown.expect(
MessageDoesNotExistException.class,
String.format("(1-3-EXAMPLE-4-%d)", MESSAGE_ID));
runFlow();
}
}

View file

@ -223,9 +223,9 @@ public class PollRequestFlowTest extends FlowTestCase<PollRequestFlow> {
@Test
public void testFailure_messageIdProvided() throws Exception {
thrown.expect(UnexpectedMessageIdException.class);
setEppInput("poll_with_id.xml");
assertTransactionalFlow(false);
thrown.expect(UnexpectedMessageIdException.class);
runFlow();
}
}

View file

@ -66,8 +66,8 @@ public abstract class LoginFlowTestCase extends FlowTestCase<LoginFlow> {
// Also called in subclasses.
void doFailingTest(String xmlFilename, Class<? extends Exception> exception)
throws Exception {
thrown.expect(exception);
setEppInput(xmlFilename);
thrown.expect(exception);
runFlow();
}

View file

@ -47,8 +47,8 @@ public class LogoutFlowTest extends FlowTestCase<LogoutFlow> {
@Test
public void testFailure() throws Exception {
thrown.expect(NotLoggedInException.class);
sessionMetadata.setClientId(null); // Turn off the implicit login
thrown.expect(NotLoggedInException.class);
runFlow();
}
}

View file

@ -136,19 +136,19 @@ public class DirectoryGroupsConnectionTest {
@Test
public void test_addMemberToGroup_handlesExceptionThrownByDirectoryService() throws Exception {
thrown.expect(GoogleJsonResponseException.class);
when(membersInsert.execute()).thenThrow(
makeResponseException(SC_INTERNAL_SERVER_ERROR, "Could not contact Directory server."));
thrown.expect(GoogleJsonResponseException.class);
runAddMemberTest();
}
@Test
public void test_addMemberToGroup_handlesMemberKeyNotFoundException() throws Exception {
thrown.expect(RuntimeException.class,
"Adding member jim@example.com to group spam@example.com "
+ "failed because the member wasn't found.");
when(membersInsert.execute()).thenThrow(
makeResponseException(SC_NOT_FOUND, "Resource Not Found: memberKey"));
thrown.expect(RuntimeException.class,
"Adding member jim@example.com to group spam@example.com "
+ "failed because the member wasn't found.");
connection.addMemberToGroup("spam@example.com", "jim@example.com", Role.MEMBER);
}
@ -196,9 +196,9 @@ public class DirectoryGroupsConnectionTest {
@Test
public void test_createGroup_handlesExceptionThrownByDirectoryService() throws Exception {
thrown.expect(GoogleJsonResponseException.class);
when(groupsInsert.execute()).thenThrow(
makeResponseException(SC_INTERNAL_SERVER_ERROR, "Could not contact Directory server."));
thrown.expect(GoogleJsonResponseException.class);
runCreateGroupTest();
}

View file

@ -93,8 +93,8 @@ public class RegistrarCreditTest extends EntityTestCase {
@Test
public void testFailure_CurrencyDoesNotMatchTldCurrency() throws Exception {
thrown.expect(IllegalArgumentException.class, "currency");
assertThat(Registry.get("tld").getCurrency()).isEqualTo(USD);
thrown.expect(IllegalArgumentException.class, "currency");
promoCredit.asBuilder().setTld("tld").setCurrency(JPY).build();
}
}

View file

@ -159,16 +159,15 @@ public class TimedTransitionPropertyTest {
@Test
public void testFailure_noValuesAfterSimulatedEmptyLoad() throws Exception {
thrown.expect(IllegalStateException.class);
timedString = forMapify("0", StringTimedTransition.class);
// Simulate a load from datastore by clearing, but don't insert any transitions.
timedString.clear();
thrown.expect(IllegalStateException.class);
timedString.checkValidity();
}
@Test
public void testFailure_noValueAtStartOfTimeAfterSimulatedLoad() throws Exception {
thrown.expect(IllegalStateException.class);
// Just for testing, don't extract transitions from a TimedTransitionProperty in real code.
StringTimedTransition transition1 = timedString.get(DATE_1);
timedString = forMapify("0", StringTimedTransition.class);
@ -176,6 +175,7 @@ public class TimedTransitionPropertyTest {
// omit a transition corresponding to START_OF_TIME.
timedString.clear();
timedString.put(DATE_1, transition1);
thrown.expect(IllegalStateException.class);
timedString.checkValidity();
}
}

View file

@ -108,10 +108,10 @@ public class EscrowTaskRunnerTest {
@Test
public void testRun_lockIsntAvailable_throws503() throws Exception {
String lockName = task.getClass().getSimpleName() + " lol";
thrown.expect(ServiceUnavailableException.class, "Lock in use: " + lockName);
clock.setTo(DateTime.parse("2006-06-06T00:30:00Z"));
persistResource(
Cursor.create(CursorType.RDE_STAGING, DateTime.parse("2006-06-06TZ"), registry));
thrown.expect(ServiceUnavailableException.class, "Lock in use: " + lockName);
Lock.executeWithLocks(
new Callable<Void>() {
@Override

View file

@ -191,9 +191,9 @@ public class GhostrydeTest {
byte[] ciphertext = bsOut.toByteArray();
korruption(ciphertext, ciphertext.length / 2);
thrown.expect(IllegalStateException.class, "tampering");
ByteArrayInputStream bsIn = new ByteArrayInputStream(ciphertext);
thrown.expect(IllegalStateException.class, "tampering");
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
}
@ -219,9 +219,9 @@ public class GhostrydeTest {
byte[] ciphertext = bsOut.toByteArray();
korruption(ciphertext, ciphertext.length / 2);
thrown.expect(PGPException.class);
ByteArrayInputStream bsIn = new ByteArrayInputStream(ciphertext);
thrown.expect(PGPException.class);
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
}
@ -245,10 +245,10 @@ public class GhostrydeTest {
output.write(data);
}
ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
thrown.expect(
PGPException.class,
"Message was encrypted for keyid a59c132f3589a1d5 but ours is c9598c84ec70b9fd");
ByteArrayInputStream bsIn = new ByteArrayInputStream(bsOut.toByteArray());
try (Ghostryde.Decryptor decryptor = ghost.openDecryptor(bsIn, privateKey)) {
ByteStreams.copy(decryptor, ByteStreams.nullOutputStream());
}

View file

@ -152,30 +152,30 @@ public class RdeImportUtilsTest extends ShardableTestCase {
/** Verifies thrown error when tld in escrow file is not in the registry */
@Test
public void testValidateEscrowFile_tldNotFound() throws Exception {
thrown.expect(IllegalArgumentException.class, "Tld 'badtld' not found in the registry");
xmlInput = DEPOSIT_BADTLD_XML.openBufferedStream();
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
thrown.expect(IllegalArgumentException.class, "Tld 'badtld' not found in the registry");
rdeImportUtils.validateEscrowFileForImport("invalid-deposit-badtld.xml");
}
/** Verifies thrown errer when tld in escrow file is not in PREDELEGATION state */
@Test
public void testValidateEscrowFile_tldWrongState() throws Exception {
xmlInput = DEPOSIT_GETLD_XML.openBufferedStream();
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
thrown.expect(
IllegalArgumentException.class,
"Tld 'getld' is in state GENERAL_AVAILABILITY and cannot be imported");
xmlInput = DEPOSIT_GETLD_XML.openBufferedStream();
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
rdeImportUtils.validateEscrowFileForImport("invalid-deposit-getld.xml");
}
/** Verifies thrown error when registrar in escrow file is not in the registry */
@Test
public void testValidateEscrowFile_badRegistrar() throws Exception {
thrown.expect(
IllegalArgumentException.class, "Registrar 'RegistrarY' not found in the registry");
xmlInput = DEPOSIT_BADREGISTRAR_XML.openBufferedStream();
when(gcsUtils.openInputStream(any(GcsFilename.class))).thenReturn(xmlInput);
thrown.expect(
IllegalArgumentException.class, "Registrar 'RegistrarY' not found in the registry");
rdeImportUtils.validateEscrowFileForImport("invalid-deposit-badregistrar.xml");
}

View file

@ -220,15 +220,15 @@ public class DriveConnectionTest {
@Test
public void testCreateOrUpdateFile_throwsExceptionWhenMultipleFilesWithNameAlreadyExist()
throws Exception {
thrown.expect(IllegalStateException.class,
"Could not update file 'title' in Drive folder id 'driveFolderId' "
+ "because multiple files with that name already exist.");
ChildList childList = new ChildList()
.setItems(ImmutableList.of(
new ChildReference().setId("id1"),
new ChildReference().setId("id2")))
.setNextPageToken(null);
when(childrenList.execute()).thenReturn(childList);
thrown.expect(IllegalStateException.class,
"Could not update file 'title' in Drive folder id 'driveFolderId' "
+ "because multiple files with that name already exist.");
driveConnection.createOrUpdateFile("title", MediaType.WEBM_VIDEO, "driveFolderId", DATA);
}

View file

@ -0,0 +1,69 @@
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.testing;
import static com.google.common.truth.Truth.assertAbout;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.EppXmlTransformer.marshal;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import com.google.common.truth.AbstractVerb.DelegatedVerb;
import com.google.common.truth.FailureStrategy;
import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import google.registry.flows.EppException;
import google.registry.model.eppcommon.Trid;
import google.registry.model.eppoutput.EppOutput;
import google.registry.model.eppoutput.EppResponse;
import google.registry.testing.TruthChainer.And;
import google.registry.xml.ValidationMode;
import google.registry.xml.XmlException;
/** Utility methods for asserting things about {@link EppException} instances. */
public class EppExceptionSubject extends Subject<EppExceptionSubject, EppException> {
public EppExceptionSubject(FailureStrategy strategy, EppException subject) {
super(strategy, subject);
}
public And<EppExceptionSubject> hasMessage(String expected) {
assertThat(actual()).hasMessage(expected);
return new And<>(this);
}
public And<EppExceptionSubject> marshalsToXml() {
// Attempt to marshal the exception to EPP. If it doesn't work, this will throw.
try {
marshal(
EppOutput.create(new EppResponse.Builder()
.setTrid(Trid.create(null))
.setResult(actual().getResult())
.setExecutionTime(START_OF_TIME)
.build()),
ValidationMode.STRICT);
} catch (XmlException e) {
fail("fails to marshal to XML: " + e.getMessage());
}
return new And<>(this);
}
public static DelegatedVerb<EppExceptionSubject, EppException> assertAboutEppExceptions() {
return assertAbout(new SubjectFactory<EppExceptionSubject, EppException>() {
@Override
public EppExceptionSubject getSubject(FailureStrategy strategy, EppException subject) {
return new EppExceptionSubject(strategy, subject);
}});
}
}

View file

@ -17,15 +17,9 @@ package google.registry.testing;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.nullToEmpty;
import static com.google.common.base.Throwables.getRootCause;
import static google.registry.flows.EppXmlTransformer.marshal;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import google.registry.flows.EppException;
import google.registry.model.eppcommon.Trid;
import google.registry.model.eppoutput.EppOutput;
import google.registry.model.eppoutput.EppResponse;
import google.registry.util.Clock;
import google.registry.util.SystemClock;
import google.registry.xml.ValidationMode;
import javax.annotation.Nullable;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
@ -37,8 +31,6 @@ import org.junit.runners.model.Statement;
*/
public class ExceptionRule implements TestRule {
private static final Clock CLOCK = new SystemClock();
@Nullable
Class<? extends Throwable> expectedExceptionClass;
@ -68,14 +60,7 @@ public class ExceptionRule implements TestRule {
throw e; // We didn't expect this so pass it through.
}
if (e instanceof EppException) {
// Attempt to marshall the exception to EPP. If it doesn't work, this will throw.
marshal(
EppOutput.create(new EppResponse.Builder()
.setTrid(Trid.create(null))
.setResult(((EppException) e).getResult())
.setExecutionTime(CLOCK.nowUtc())
.build()),
ValidationMode.STRICT);
assertAboutEppExceptions().that((EppException) e).marshalsToXml();
}
}
}};

View file

@ -65,27 +65,27 @@ public class TmchCertificateAuthorityTest {
@Test
public void testFailure_prodRootExpired() throws Exception {
thrown.expectRootCause(
CertificateExpiredException.class, "NotAfter: Sun Jul 23 23:59:59 UTC 2023");
configRule.useTmchProdCert();
clock.setTo(DateTime.parse("2024-01-01T00:00:00Z"));
thrown.expectRootCause(
CertificateExpiredException.class, "NotAfter: Sun Jul 23 23:59:59 UTC 2023");
TmchCertificateAuthority.getRoot();
}
@Test
public void testFailure_prodRootNotYetValid() throws Exception {
thrown.expectRootCause(CertificateNotYetValidException.class,
"NotBefore: Wed Jul 24 00:00:00 UTC 2013");
configRule.useTmchProdCert();
clock.setTo(DateTime.parse("2000-01-01T00:00:00Z"));
thrown.expectRootCause(CertificateNotYetValidException.class,
"NotBefore: Wed Jul 24 00:00:00 UTC 2013");
TmchCertificateAuthority.getRoot();
}
@Test
public void testFailure_crlDoesntMatchCerts() throws Exception {
thrown.expectRootCause(SignatureException.class, "Signature does not match");
// Use the prod cl, which won't match our test certificate.
TmchCrl.set(readResourceUtf8(TmchCertificateAuthority.class, "icann-tmch.crl"));
thrown.expectRootCause(SignatureException.class, "Signature does not match");
TmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE));
}
@ -96,8 +96,8 @@ public class TmchCertificateAuthorityTest {
@Test
public void testFailure_verifySignatureDoesntMatch() throws Exception {
thrown.expectRootCause(SignatureException.class, "Signature does not match");
configRule.useTmchProdCert();
thrown.expectRootCause(SignatureException.class, "Signature does not match");
TmchCertificateAuthority.verify(loadCertificate(GOOD_TEST_CERTIFICATE));
}

View file

@ -65,8 +65,8 @@ public class TmchXmlSignatureTest {
public void wrongCertificateAuthority() throws Exception {
configRule.useTmchProdCert();
thrown.expectRootCause(SignatureException.class, "Signature does not match");
smdData = loadSmd("active/Court-Agent-Arabic-Active.smd");
thrown.expectRootCause(SignatureException.class, "Signature does not match");
TmchXmlSignature.verify(smdData);
}

View file

@ -1145,12 +1145,12 @@ public class CreateRegistrarCommandTest extends CommandTestCase<CreateRegistrarC
@Test
public void testFailure_alreadyExists() throws Exception {
thrown.expect(IllegalStateException.class, "Registrar existing already exists");
persistResource(new Registrar.Builder()
.setClientId("existing")
.setIanaIdentifier(1L)
.setType(Registrar.Type.REAL)
.build());
thrown.expect(IllegalStateException.class, "Registrar existing already exists");
runCommand(
"--name=blobio",
"--password=some_password",

View file

@ -15,6 +15,7 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED;
import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.persistReservedList;
@ -86,9 +87,9 @@ public class CreateReservedListCommandTest extends
@Test
public void testFailure_reservedListWithThatNameAlreadyExists() throws Exception {
thrown.expect(IllegalArgumentException.class, "A reserved list already exists by this name");
ReservedList rl = persistReservedList("xn--q9jyb4c_foo", "jones,FULLY_BLOCKED");
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setReservedLists(rl).build());
thrown.expect(IllegalArgumentException.class, "A reserved list already exists by this name");
runCommandForced("--name=xn--q9jyb4c_foo", "--input=" + reservedTermsPath);
}
@ -169,9 +170,13 @@ public class CreateReservedListCommandTest extends
}
private void runNameTestExpectedFailure(String name, String expectedErrorMsg) throws Exception {
thrown.expect(IllegalArgumentException.class, expectedErrorMsg);
runCommandForced("--name=" + name, "--input=" + reservedTermsPath);
assertThat(ReservedList.get(name)).isAbsent();
try {
runCommandForced("--name=" + name, "--input=" + reservedTermsPath);
assertWithMessage("Expected IllegalArgumentException to be thrown").fail();
} catch (IllegalArgumentException e) {
assertThat(ReservedList.get(name)).isAbsent();
assertThat(e).hasMessage(expectedErrorMsg);
}
}
private void runNameTestWithOverride(String name) throws Exception {

View file

@ -267,8 +267,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test
public void testFailure_bothTldStateFlags() throws Exception {
thrown.expect(IllegalArgumentException.class);
DateTime now = DateTime.now(UTC);
thrown.expect(IllegalArgumentException.class);
runCommandForced(
String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now.plus(1)),
"--initial_tld_state=GENERAL_AVAILABILITY",
@ -306,8 +306,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test
public void testFailure_alreadyExists() throws Exception {
thrown.expect(IllegalStateException.class);
createTld("xn--q9jyb4c");
thrown.expect(IllegalStateException.class);
runCommandForced("--roid_suffix=NOTDUPE", "xn--q9jyb4c");
}

View file

@ -15,6 +15,7 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistPremiumList;
@ -55,9 +56,13 @@ public class DeletePremiumListCommandTest extends CommandTestCase<DeletePremiumL
PremiumList premiumList = persistPremiumList("xn--q9jyb4c", "blah,USD 100");
createTld("xn--q9jyb4c");
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setPremiumList(premiumList).build());
thrown.expect(IllegalArgumentException.class,
"Cannot delete premium list because it is used on these tld(s): xn--q9jyb4c");
runCommandForced("--name=" + premiumList.getName());
assertThat(PremiumList.get(premiumList.getName())).isPresent();
try {
runCommandForced("--name=" + premiumList.getName());
assertWithMessage("Expected IllegalArgumentException to be thrown").fail();
} catch (IllegalArgumentException e) {
assertThat(PremiumList.get(premiumList.getName())).isPresent();
assertThat(e)
.hasMessage("Cannot delete premium list because it is used on these tld(s): xn--q9jyb4c");
}
}
}

View file

@ -15,6 +15,7 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistReservedList;
import static google.registry.testing.DatastoreHelper.persistResource;
@ -53,9 +54,13 @@ public class DeleteReservedListCommandTest extends CommandTestCase<DeleteReserve
public void testFailure_whenReservedListIsInUse() throws Exception {
createTld("xn--q9jyb4c");
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setReservedLists(reservedList).build());
thrown.expect(IllegalArgumentException.class,
"Cannot delete reserved list because it is used on these tld(s): xn--q9jyb4c");
runCommandForced("--name=" + reservedList.getName());
assertThat(ReservedList.get(reservedList.getName())).isPresent();
try {
runCommandForced("--name=" + reservedList.getName());
assertWithMessage("Expected IllegalArgumentException to be thrown").fail();
} catch (IllegalArgumentException e) {
assertThat(ReservedList.get(reservedList.getName())).isPresent();
assertThat(e).hasMessage(
"Cannot delete reserved list because it is used on these tld(s): xn--q9jyb4c");
}
}
}

View file

@ -113,10 +113,10 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
@Test
public void testFailure_contact_oneDoesNotExist() throws Exception {
persistActiveContact("sh8013");
thrown.expect(
NullPointerException.class,
"Could not load resource for key: Key<?>(ContactResource(\"3-ROID\"))");
persistActiveContact("sh8013");
runCommand(
"agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjItUk9JRAw",
"agR0ZXN0chsLEg9Db250YWN0UmVzb3VyY2UiBjMtUk9JRAw");
@ -159,10 +159,10 @@ public class GetResourceByKeyCommandTest extends CommandTestCase<GetResourceByKe
@Test
public void testFailure_host_oneDoesNotExist() throws Exception {
persistActiveHost("ns1.example.tld");
thrown.expect(
NullPointerException.class,
"Could not load resource for key: Key<?>(HostResource(\"3-ROID\"))");
persistActiveHost("ns1.example.tld");
runCommand(
"agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjItUk9JRAw",
"agR0ZXN0chgLEgxIb3N0UmVzb3VyY2UiBjMtUk9JRAw");

View file

@ -50,8 +50,8 @@ public class GetTldCommandTest extends CommandTestCase<GetTldCommand> {
@Test
public void testFailure_oneTldDoesNotExist() throws Exception {
thrown.expect(IllegalArgumentException.class);
createTld("xn--q9jyb4c");
thrown.expect(IllegalArgumentException.class);
runCommand("xn--q9jyb4c", "example");
}
}

View file

@ -15,13 +15,13 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource;
import static org.joda.time.DateTimeZone.UTC;
import static org.junit.Assert.fail;
import google.registry.model.host.HostResource;
import google.registry.model.registrar.Registrar;
@ -285,7 +285,7 @@ public class MutatingCommandTest {
+ "blockPremiumNames -> [false, true]\n");
try {
command.execute();
fail("Expected transaction to fail with IllegalStateException.");
assertWithMessage("Expected transaction to fail with IllegalStateException").fail();
} catch (IllegalStateException e) {
assertThat(e.getMessage()).contains("Entity changed since init() was called.");
assertThat(ofy().load().entity(host1).now()).isNull();

View file

@ -257,6 +257,7 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
@Test
public void testFailure_invalidPremiumList() throws Exception {
thrown.expect(IllegalArgumentException.class);
runCommandForced(
"--ip_whitelist=1.1.1.1",
"--registrar=blobio",
@ -266,8 +267,8 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
@Test
public void testFailure_tldExists() throws Exception {
thrown.expect(IllegalStateException.class);
createTld("blobio-sunrise");
thrown.expect(IllegalStateException.class);
runCommandForced(
"--ip_whitelist=1.1.1.1",
@ -277,13 +278,12 @@ public class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
@Test
public void testFailure_registrarExists() throws Exception {
thrown.expect(IllegalStateException.class);
Registrar registrar = Registrar.loadByClientId("TheRegistrar").asBuilder()
.setClientId("blobio-1")
.setRegistrarName("blobio-1")
.build();
persistResource(registrar);
thrown.expect(IllegalStateException.class);
runCommandForced(
"--ip_whitelist=1.1.1.1",

View file

@ -139,8 +139,8 @@ public class UpdateClaimsNoticeCommandTest extends CommandTestCase<UpdateClaimsN
@Test
public void testFailure_claimsNoticeForWrongLabel() throws Exception {
thrown.expectRootCause(InvalidChecksumException.class);
domainApplication = persistResource(newDomainApplication("bad-label.xn--q9jyb4c"));
thrown.expectRootCause(InvalidChecksumException.class);
runCommand(
"--id=4-Q9JYB4C",
"--tcn_id=370d0b7c9223372036854775807",
@ -150,12 +150,11 @@ public class UpdateClaimsNoticeCommandTest extends CommandTestCase<UpdateClaimsN
@Test
public void testFailure_sunriseApplication() throws Exception {
thrown.expect(IllegalArgumentException.class);
// Add an encoded signed mark to the application to make it a sunrise application.
domainApplication = persistResource(domainApplication.asBuilder()
.setEncodedSignedMarks(ImmutableList.of(EncodedSignedMark.create("base64", "AAAAA")))
.build());
thrown.expect(IllegalArgumentException.class);
runCommand(
"--id=1-Q9JYB4C",

View file

@ -62,7 +62,6 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
@Test
public void testFailure_noPasscodeOnChangeToReal() throws Exception {
thrown.expect(IllegalArgumentException.class, "--passcode is required for REAL registrars.");
persistResource(
loadByClientId("NewRegistrar")
.asBuilder()
@ -70,6 +69,7 @@ public class UpdateRegistrarCommandTest extends CommandTestCase<UpdateRegistrarC
.setIanaIdentifier(null)
.setPhonePasscode(null)
.build());
thrown.expect(IllegalArgumentException.class, "--passcode is required for REAL registrars.");
runCommand("--registrar_type=REAL", "--iana_id=1000", "--force", "NewRegistrar");
}

View file

@ -91,60 +91,60 @@ public class UpdateSmdCommandTest extends CommandTestCase<UpdateSmdCommand> {
@Test
public void testFailure_invalidSmd() throws Exception {
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
String smdFile = writeToTmpFile(INVALID_SMD);
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
}
@Test
public void testFailure_revokedSmd() throws Exception {
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
DateTime now = new DateTime(UTC);
SignedMarkRevocationList.create(now, ImmutableMap.of(ACTIVE_SMD_ID, now)).save();
String smdFile = writeToTmpFile(ACTIVE_SMD);
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
}
@Test
public void testFailure_revokedTmv() throws Exception {
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
String smdFile = writeToTmpFile(REVOKED_TMV_SMD);
thrown.expectRootCause(ParameterValuePolicyErrorException.class);
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
}
@Test
public void testFailure_unparseableXml() throws Exception {
thrown.expectRootCause(ParameterValueSyntaxErrorException.class);
String smdFile = writeToTmpFile(base64().encode("This is not XML!".getBytes(UTF_8)));
thrown.expectRootCause(ParameterValueSyntaxErrorException.class);
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
}
@Test
public void testFailure_badlyEncodedData() throws Exception {
thrown.expectRootCause(ParameterValueSyntaxErrorException.class);
String smdFile = writeToTmpFile("Bad base64 data ~!@#$#@%%$#^$%^&^**&^)(*)(_".getBytes(UTF_8));
thrown.expectRootCause(ParameterValueSyntaxErrorException.class);
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
}
@Test
public void testFailure_wrongLabel() throws Exception {
thrown.expectRootCause(RequiredParameterMissingException.class);
String smdFile = writeToTmpFile(DIFFERENT_LABEL_SMD);
thrown.expectRootCause(RequiredParameterMissingException.class);
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
}
@Test
public void testFailure_nonExistentApplication() throws Exception {
thrown.expectRootCause(IllegalArgumentException.class);
String smdFile = writeToTmpFile(ACTIVE_SMD);
thrown.expectRootCause(IllegalArgumentException.class);
runCommand("--id=3-Q9JYB4C", "--smd=" + smdFile);
}
@Test
public void testFailure_deletedApplication() throws Exception {
thrown.expectRootCause(IllegalArgumentException.class);
persistResource(domainApplication.asBuilder().setDeletionTime(new DateTime(UTC)).build());
String smdFile = writeToTmpFile(ACTIVE_SMD);
thrown.expectRootCause(IllegalArgumentException.class);
runCommand("--id=2-Q9JYB4C", "--smd=" + smdFile);
}
}

View file

@ -481,8 +481,6 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
@Test
public void testFailure_setCurrentTldState_outOfOrder() throws Exception {
thrown.expect(
IllegalArgumentException.class, "The TLD states are chronologically out of order");
persistResource(
Registry.get("xn--q9jyb4c").asBuilder()
.setTldStateTransitions(
@ -490,14 +488,13 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
START_OF_TIME, TldState.PREDELEGATION,
now.minusMonths(1), TldState.GENERAL_AVAILABILITY))
.build());
thrown.expect(
IllegalArgumentException.class, "The TLD states are chronologically out of order");
runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c");
}
@Test
public void testFailure_setCurrentTldState_laterTransitionScheduled() throws Exception {
thrown.expect(
IllegalArgumentException.class,
" when there is a later transition already scheduled");
persistResource(
Registry.get("xn--q9jyb4c").asBuilder()
.setTldStateTransitions(
@ -505,14 +502,14 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
START_OF_TIME, TldState.PREDELEGATION,
now.plusMonths(1), TldState.GENERAL_AVAILABILITY))
.build());
thrown.expect(
IllegalArgumentException.class,
" when there is a later transition already scheduled");
runCommandForced("--set_current_tld_state=SUNRISE", "xn--q9jyb4c");
}
@Test
public void testFailure_setCurrentTldState_inProduction() throws Exception {
thrown.expect(
IllegalArgumentException.class,
"--set_current_tld_state is not safe to use in production.");
persistResource(
Registry.get("xn--q9jyb4c").asBuilder()
.setTldStateTransitions(
@ -520,6 +517,9 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
START_OF_TIME, TldState.PREDELEGATION,
now.minusMonths(1), TldState.GENERAL_AVAILABILITY))
.build());
thrown.expect(
IllegalArgumentException.class,
"--set_current_tld_state is not safe to use in production.");
runCommandInEnvironment(
RegistryToolEnvironment.PRODUCTION,
"--set_current_tld_state=SUNRISE",

View file

@ -45,101 +45,101 @@ public class UploadClaimsListCommandTest extends CommandTestCase<UploadClaimsLis
}
public void testFailure_wrongNumberOfFieldsOnFirstLine() throws Exception {
thrown.expect(IllegalArgumentException.class);
String filename = writeToTmpFile(
"1,2012-08-16T00:00:00.0Z,random-extra-field",
"DNL,lookup-key,insertion-datetime",
"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);
}
public void testFailure_wrongVersion() throws Exception {
thrown.expect(IllegalArgumentException.class);
String filename = writeToTmpFile(
"2,2012-08-16T00:00:00.0Z",
"DNL,lookup-key,insertion-datetime",
"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);
}
public void testFailure_badCreationTime() throws Exception {
thrown.expect(IllegalArgumentException.class);
String filename = writeToTmpFile(
"1,foo",
"DNL,lookup-key,insertion-datetime",
"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);
}
public void testFailure_badFirstHeader() throws Exception {
thrown.expect(IllegalArgumentException.class);
String filename = writeToTmpFile(
"1,foo",
"SNL,lookup-key,insertion-datetime",
"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);
}
public void testFailure_badSecondHeader() throws Exception {
thrown.expect(IllegalArgumentException.class);
String filename = writeToTmpFile(
"1,foo",
"DNL,lookup-keys,insertion-datetime",
"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);
}
public void testFailure_badThirdHeader() throws Exception {
thrown.expect(IllegalArgumentException.class);
String filename = writeToTmpFile(
"1,foo",
"DNL,lookup-key,insertion-datetimes",
"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);
}
public void testFailure_wrongNumberOfHeaders() throws Exception {
thrown.expect(IllegalArgumentException.class);
String filename = writeToTmpFile(
"1,foo",
"DNL,lookup-key,insertion-datetime,extra-field",
"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);
}
public void testFailure_wrongNumberOfFields() throws Exception {
thrown.expect(IllegalArgumentException.class);
String filename = writeToTmpFile(
"1,foo",
"DNL,lookup-key,insertion-datetime",
"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);
}
public void testFailure_badInsertionTime() throws Exception {
thrown.expect(IllegalArgumentException.class);
String filename = writeToTmpFile(
"1,foo",
"DNL,lookup-key,insertion-datetime",
"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);
}

View file

@ -68,8 +68,8 @@ public class XjcObjectTest {
@Test
public void testMarshalValidation() throws Exception {
XjcRdeDeposit deposit = unmarshalFullDeposit();
thrown.expect(Throwable.class, "pattern '\\w{1,13}' for type 'depositIdType'");
deposit.setId("");
thrown.expect(Throwable.class, "pattern '\\w{1,13}' for type 'depositIdType'");
deposit.marshal(new ByteArrayOutputStream(), UTF_8);
}