Re-add EppException marshalling assertions in host flow tests

Apologies for the reformatting, but this refactoring is quite rote and it's
definitely a bigger use of total time to perform the reformatting individually
than to simply do it file-wide.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=179238745
This commit is contained in:
mcilwain 2017-12-15 14:17:32 -08:00 committed by Ben McIlwain
parent e17109a0eb
commit 34699465d5
5 changed files with 514 additions and 390 deletions

View file

@ -17,8 +17,10 @@ package google.registry.flows.host;
import static google.registry.model.eppoutput.CheckData.HostCheck.create; import static google.registry.model.eppoutput.CheckData.HostCheck.create;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.expectThrows;
import google.registry.flows.EppException;
import google.registry.flows.ResourceCheckFlowTestCase; import google.registry.flows.ResourceCheckFlowTestCase;
import google.registry.flows.exceptions.TooManyResourceChecksException; import google.registry.flows.exceptions.TooManyResourceChecksException;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
@ -76,7 +78,8 @@ public class HostCheckFlowTest extends ResourceCheckFlowTestCase<HostCheckFlow,
@Test @Test
public void testTooManyIds() throws Exception { public void testTooManyIds() throws Exception {
setEppInput("host_check_51.xml"); setEppInput("host_check_51.xml");
assertThrows(TooManyResourceChecksException.class, this::runFlow); EppException thrown = expectThrows(TooManyResourceChecksException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test

View file

@ -24,8 +24,8 @@ import static google.registry.testing.DatastoreHelper.persistActiveDomain;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
@ -34,6 +34,7 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.EppXmlTransformer.IpAddressVersionMismatchException; import google.registry.flows.EppXmlTransformer.IpAddressVersionMismatchException;
import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.exceptions.ResourceAlreadyExistsException; import google.registry.flows.exceptions.ResourceAlreadyExistsException;
@ -60,9 +61,7 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
private void setEppHostCreateInput(String hostName, String hostAddrs) { private void setEppHostCreateInput(String hostName, String hostAddrs) {
setEppInput( setEppInput(
"host_create.xml", "host_create.xml",
ImmutableMap.of( ImmutableMap.of("HOSTNAME", hostName, "HOSTADDRS", (hostAddrs == null) ? "" : hostAddrs));
"HOSTNAME", hostName,
"HOSTADDRS", (hostAddrs == null) ? "" : hostAddrs));
} }
private void setEppHostCreateInputWithIps(String hostName) { private void setEppHostCreateInputWithIps(String hostName) {
@ -83,8 +82,10 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
assertTransactionalFlow(true); assertTransactionalFlow(true);
runFlowAssertResponse(loadFile("host_create_response.xml")); runFlowAssertResponse(loadFile("host_create_response.xml"));
// Check that the host was created and persisted with a history entry. // Check that the host was created and persisted with a history entry.
assertAboutHosts().that(reloadResourceByForeignKey()) assertAboutHosts()
.hasLastSuperordinateChange(null).and() .that(reloadResourceByForeignKey())
.hasLastSuperordinateChange(null)
.and()
.hasOnlyOneHistoryEntryWhich() .hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.HOST_CREATE); .hasType(HistoryEntry.Type.HOST_CREATE);
assertNoBillingEvents(); assertNoBillingEvents();
@ -126,7 +127,8 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
createTlds("bar.tld", "tld"); createTlds("bar.tld", "tld");
setEppHostCreateInputWithIps("ns1.bar.tld"); setEppHostCreateInputWithIps("ns1.bar.tld");
assertThrows(HostNameTooShallowException.class, this::runFlow); EppException thrown = expectThrows(HostNameTooShallowException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -154,7 +156,8 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
setEppHostCreateInput("ns1.example.tld", null); setEppHostCreateInput("ns1.example.tld", null);
createTld("tld"); createTld("tld");
persistActiveDomain("example.tld"); persistActiveDomain("example.tld");
assertThrows(SubordinateHostMustHaveIpException.class, this::runFlow); EppException thrown = expectThrows(SubordinateHostMustHaveIpException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -162,7 +165,8 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
setEppHostCreateInputWithIps("ns1.example.external"); setEppHostCreateInputWithIps("ns1.example.external");
createTld("tld"); createTld("tld");
persistActiveDomain("example.tld"); persistActiveDomain("example.tld");
assertThrows(UnexpectedExternalHostIpException.class, this::runFlow); EppException thrown = expectThrows(UnexpectedExternalHostIpException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -178,7 +182,8 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
public void testFailure_superordinateInPendingDelete() throws Exception { public void testFailure_superordinateInPendingDelete() throws Exception {
setEppHostCreateInputWithIps("ns1.example.tld"); setEppHostCreateInputWithIps("ns1.example.tld");
createTld("tld"); createTld("tld");
persistResource(newDomainResource("example.tld") persistResource(
newDomainResource("example.tld")
.asBuilder() .asBuilder()
.setDeletionTime(clock.nowUtc().plusDays(35)) .setDeletionTime(clock.nowUtc().plusDays(35))
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE)) .setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
@ -206,7 +211,8 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
@Test @Test
public void testFailure_nonLowerCaseHostname() throws Exception { public void testFailure_nonLowerCaseHostname() throws Exception {
setEppHostCreateInput("ns1.EXAMPLE.tld", null); setEppHostCreateInput("ns1.EXAMPLE.tld", null);
assertThrows(HostNameNotLowerCaseException.class, this::runFlow); EppException thrown = expectThrows(HostNameNotLowerCaseException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -220,13 +226,15 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
@Test @Test
public void testFailure_nonCanonicalHostname() throws Exception { public void testFailure_nonCanonicalHostname() throws Exception {
setEppHostCreateInput("ns1.example.tld.", null); setEppHostCreateInput("ns1.example.tld.", null);
assertThrows(HostNameNotNormalizedException.class, this::runFlow); EppException thrown = expectThrows(HostNameNotNormalizedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_longHostName() throws Exception { public void testFailure_longHostName() throws Exception {
setEppHostCreateInputWithIps("a" + Strings.repeat(".labelpart", 25) + ".tld"); setEppHostCreateInputWithIps("a" + Strings.repeat(".labelpart", 25) + ".tld");
assertThrows(HostNameTooLongException.class, this::runFlow); EppException thrown = expectThrows(HostNameTooLongException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -236,13 +244,15 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
"<host:addr ip=\"v4\">192.0.2.2</host:addr>\n" "<host:addr ip=\"v4\">192.0.2.2</host:addr>\n"
+ "<host:addr ip=\"v6\">192.0.2.29</host:addr>\n" + "<host:addr ip=\"v6\">192.0.2.29</host:addr>\n"
+ "<host:addr ip=\"v6\">1080:0:0:0:8:800:200C:417A</host:addr>"); + "<host:addr ip=\"v6\">1080:0:0:0:8:800:200C:417A</host:addr>");
assertThrows(IpAddressVersionMismatchException.class, this::runFlow); EppException thrown = expectThrows(IpAddressVersionMismatchException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
private void doFailingHostNameTest(String hostName, Class<? extends Throwable> exception) private void doFailingHostNameTest(String hostName, Class<? extends EppException> exception)
throws Exception { throws Exception {
setEppHostCreateInputWithIps(hostName); setEppHostCreateInputWithIps(hostName);
assertThrows(exception, this::runFlow); EppException thrown = expectThrows(exception, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -279,7 +289,8 @@ public class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Hos
public void testFailure_ccTldInBailiwick() throws Exception { public void testFailure_ccTldInBailiwick() throws Exception {
createTld("co.uk"); createTld("co.uk");
setEppHostCreateInputWithIps("foo.co.uk"); setEppHostCreateInputWithIps("foo.co.uk");
assertThrows(HostNameTooShallowException.class, this::runFlow); EppException thrown = expectThrows(HostNameTooShallowException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test

View file

@ -23,14 +23,15 @@ import static google.registry.testing.DatastoreHelper.newHostResource;
import static google.registry.testing.DatastoreHelper.persistActiveHost; import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistDeletedHost; import static google.registry.testing.DatastoreHelper.persistDeletedHost;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.HostResourceSubject.assertAboutHosts; import static google.registry.testing.HostResourceSubject.assertAboutHosts;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued; import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException; import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
@ -75,7 +76,8 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
assertAboutHosts().that(deletedHost).hasStatusValue(StatusValue.PENDING_DELETE); assertAboutHosts().that(deletedHost).hasStatusValue(StatusValue.PENDING_DELETE);
assertAsyncDeletionTaskEnqueued( assertAsyncDeletionTaskEnqueued(
deletedHost, "TheRegistrar", Trid.create("ABC-12345", "server-trid"), false); deletedHost, "TheRegistrar", Trid.create("ABC-12345", "server-trid"), false);
assertAboutHosts().that(deletedHost) assertAboutHosts()
.that(deletedHost)
.hasOnlyOneHistoryEntryWhich() .hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.HOST_PENDING_DELETE); .hasType(HistoryEntry.Type.HOST_PENDING_DELETE);
assertNoBillingEvents(); assertNoBillingEvents();
@ -130,7 +132,8 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
public void testFailure_unauthorizedClient() throws Exception { public void testFailure_unauthorizedClient() throws Exception {
sessionMetadata.setClientId("NewRegistrar"); sessionMetadata.setClientId("NewRegistrar");
persistActiveHost("ns1.example.tld"); persistActiveHost("ns1.example.tld");
assertThrows(ResourceNotOwnedException.class, this::runFlow); EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -144,7 +147,8 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
assertAboutHosts().that(deletedHost).hasStatusValue(StatusValue.PENDING_DELETE); assertAboutHosts().that(deletedHost).hasStatusValue(StatusValue.PENDING_DELETE);
assertAsyncDeletionTaskEnqueued( assertAsyncDeletionTaskEnqueued(
deletedHost, "NewRegistrar", Trid.create("ABC-12345", "server-trid"), true); deletedHost, "NewRegistrar", Trid.create("ABC-12345", "server-trid"), true);
assertAboutHosts().that(deletedHost) assertAboutHosts()
.that(deletedHost)
.hasOnlyOneHistoryEntryWhich() .hasOnlyOneHistoryEntryWhich()
.hasType(HistoryEntry.Type.HOST_PENDING_DELETE); .hasType(HistoryEntry.Type.HOST_PENDING_DELETE);
assertNoBillingEvents(); assertNoBillingEvents();
@ -155,12 +159,15 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
public void testSuccess_authorizedClientReadFromSuperordinate() throws Exception { public void testSuccess_authorizedClientReadFromSuperordinate() throws Exception {
sessionMetadata.setClientId("TheRegistrar"); sessionMetadata.setClientId("TheRegistrar");
createTld("tld"); createTld("tld");
DomainResource domain = persistResource( DomainResource domain =
newDomainResource("example.tld").asBuilder() persistResource(
newDomainResource("example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("TheRegistrar") .setPersistedCurrentSponsorClientId("TheRegistrar")
.build()); .build());
persistResource( persistResource(
newHostResource("ns1.example.tld").asBuilder() newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't hurt. .setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't hurt.
.setSuperordinateDomain(Key.create(domain)) .setSuperordinateDomain(Key.create(domain))
.build()); .build());
@ -172,16 +179,20 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
public void testFailure_unauthorizedClientReadFromSuperordinate() throws Exception { public void testFailure_unauthorizedClientReadFromSuperordinate() throws Exception {
sessionMetadata.setClientId("TheRegistrar"); sessionMetadata.setClientId("TheRegistrar");
createTld("tld"); createTld("tld");
DomainResource domain = persistResource( DomainResource domain =
newDomainResource("example.tld").asBuilder() persistResource(
newDomainResource("example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("NewRegistrar") .setPersistedCurrentSponsorClientId("NewRegistrar")
.build()); .build());
persistResource( persistResource(
newHostResource("ns1.example.tld").asBuilder() newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't help. .setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't help.
.setSuperordinateDomain(Key.create(domain)) .setSuperordinateDomain(Key.create(domain))
.build()); .build());
assertThrows(ResourceNotOwnedException.class, this::runFlow); EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -192,10 +203,14 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
DateTime now = clock.nowUtc(); DateTime now = clock.nowUtc();
DateTime requestTime = now.minusDays(1).minus(Registry.DEFAULT_AUTOMATIC_TRANSFER_LENGTH); DateTime requestTime = now.minusDays(1).minus(Registry.DEFAULT_AUTOMATIC_TRANSFER_LENGTH);
DateTime transferExpirationTime = now.minusDays(1); DateTime transferExpirationTime = now.minusDays(1);
DomainResource domain = persistResource(newDomainResource("example.tld").asBuilder() DomainResource domain =
persistResource(
newDomainResource("example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't hurt. .setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't hurt.
.addStatusValue(StatusValue.PENDING_TRANSFER) .addStatusValue(StatusValue.PENDING_TRANSFER)
.setTransferData(new TransferData.Builder() .setTransferData(
new TransferData.Builder()
.setTransferStatus(TransferStatus.PENDING) .setTransferStatus(TransferStatus.PENDING)
.setGainingClientId("NewRegistrar") .setGainingClientId("NewRegistrar")
.setTransferRequestTime(requestTime) .setTransferRequestTime(requestTime)
@ -204,7 +219,8 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
.build()) .build())
.build()); .build());
persistResource( persistResource(
newHostResource("ns1.example.tld").asBuilder() newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't hurt. .setPersistedCurrentSponsorClientId("TheRegistrar") // Shouldn't hurt.
.setSuperordinateDomain(Key.create(domain)) .setSuperordinateDomain(Key.create(domain))
.build()); .build());
@ -220,10 +236,14 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
DateTime now = clock.nowUtc(); DateTime now = clock.nowUtc();
DateTime requestTime = now.minusDays(1).minus(Registry.DEFAULT_AUTOMATIC_TRANSFER_LENGTH); DateTime requestTime = now.minusDays(1).minus(Registry.DEFAULT_AUTOMATIC_TRANSFER_LENGTH);
DateTime transferExpirationTime = now.minusDays(1); DateTime transferExpirationTime = now.minusDays(1);
DomainResource domain = persistResource(newDomainResource("example.tld").asBuilder() DomainResource domain =
persistResource(
newDomainResource("example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't help. .setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't help.
.addStatusValue(StatusValue.PENDING_TRANSFER) .addStatusValue(StatusValue.PENDING_TRANSFER)
.setTransferData(new TransferData.Builder() .setTransferData(
new TransferData.Builder()
.setTransferStatus(TransferStatus.PENDING) .setTransferStatus(TransferStatus.PENDING)
.setGainingClientId("TheRegistrar") .setGainingClientId("TheRegistrar")
.setTransferRequestTime(requestTime) .setTransferRequestTime(requestTime)
@ -232,37 +252,44 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
.build()) .build())
.build()); .build());
persistResource( persistResource(
newHostResource("ns1.example.tld").asBuilder() newHostResource("ns1.example.tld")
.asBuilder()
.setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't help. .setPersistedCurrentSponsorClientId("NewRegistrar") // Shouldn't help.
.setSuperordinateDomain(Key.create(domain)) .setSuperordinateDomain(Key.create(domain))
.build()); .build());
assertThrows(ResourceNotOwnedException.class, this::runFlow); EppException thrown = expectThrows(ResourceNotOwnedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_failfastWhenLinkedToDomain() throws Exception { public void testFailure_failfastWhenLinkedToDomain() throws Exception {
createTld("tld"); createTld("tld");
persistResource(newDomainResource("example.tld").asBuilder() persistResource(
.setNameservers(ImmutableSet.of( newDomainResource("example.tld")
Key.create(persistActiveHost("ns1.example.tld")))) .asBuilder()
.setNameservers(ImmutableSet.of(Key.create(persistActiveHost("ns1.example.tld"))))
.build()); .build());
assertThrows(ResourceToDeleteIsReferencedException.class, this::runFlow); EppException thrown = expectThrows(ResourceToDeleteIsReferencedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_failfastWhenLinkedToApplication() throws Exception { public void testFailure_failfastWhenLinkedToApplication() throws Exception {
createTld("tld"); createTld("tld");
persistResource(newDomainApplication("example.tld").asBuilder() persistResource(
.setNameservers(ImmutableSet.of( newDomainApplication("example.tld")
Key.create(persistActiveHost("ns1.example.tld")))) .asBuilder()
.setNameservers(ImmutableSet.of(Key.create(persistActiveHost("ns1.example.tld"))))
.build()); .build());
assertThrows(ResourceToDeleteIsReferencedException.class, this::runFlow); EppException thrown = expectThrows(ResourceToDeleteIsReferencedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
public void testFailure_nonLowerCaseHostname() throws Exception { public void testFailure_nonLowerCaseHostname() throws Exception {
setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "NS1.EXAMPLE.NET")); setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "NS1.EXAMPLE.NET"));
assertThrows(HostNameNotLowerCaseException.class, this::runFlow); EppException thrown = expectThrows(HostNameNotLowerCaseException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -276,7 +303,8 @@ public class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Hos
@Test @Test
public void testFailure_nonCanonicalHostname() throws Exception { public void testFailure_nonCanonicalHostname() throws Exception {
setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld.")); setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld."));
assertThrows(HostNameNotNormalizedException.class, this::runFlow); EppException thrown = expectThrows(HostNameNotNormalizedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test

View file

@ -19,13 +19,14 @@ import static google.registry.testing.DatastoreHelper.assertNoBillingEvents;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainResource; import static google.registry.testing.DatastoreHelper.newDomainResource;
import static google.registry.testing.DatastoreHelper.persistResource; import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
import static google.registry.testing.JUnitBackports.expectThrows; import static google.registry.testing.JUnitBackports.expectThrows;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
import com.googlecode.objectify.Key; import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException; import google.registry.flows.ResourceFlowUtils.ResourceDoesNotExistException;
import google.registry.flows.host.HostFlowUtils.HostNameNotLowerCaseException; import google.registry.flows.host.HostFlowUtils.HostNameNotLowerCaseException;
@ -57,9 +58,9 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
.setFullyQualifiedHostName(getUniqueIdFromCommand()) .setFullyQualifiedHostName(getUniqueIdFromCommand())
.setRepoId("1FF-FOOBAR") .setRepoId("1FF-FOOBAR")
.setPersistedCurrentSponsorClientId("my sponsor") .setPersistedCurrentSponsorClientId("my sponsor")
.setStatusValues( .setStatusValues(ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED))
ImmutableSet.of(StatusValue.CLIENT_UPDATE_PROHIBITED)) .setInetAddresses(
.setInetAddresses(ImmutableSet.of( ImmutableSet.of(
InetAddresses.forString("192.0.2.2"), InetAddresses.forString("192.0.2.2"),
InetAddresses.forString("1080:0:0:0:8:800:200C:417A"), InetAddresses.forString("1080:0:0:0:8:800:200C:417A"),
InetAddresses.forString("192.0.2.29"))) InetAddresses.forString("192.0.2.29")))
@ -89,7 +90,8 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
public void testSuccess_linked() throws Exception { public void testSuccess_linked() throws Exception {
persistHostResource(); persistHostResource();
persistResource( persistResource(
newDomainResource("example.foobar").asBuilder() newDomainResource("example.foobar")
.asBuilder()
.addNameservers(ImmutableSet.of(Key.create(persistHostResource()))) .addNameservers(ImmutableSet.of(Key.create(persistHostResource())))
.build()); .build());
assertTransactionalFlow(false); assertTransactionalFlow(false);
@ -102,16 +104,19 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
assertNoBillingEvents(); assertNoBillingEvents();
} }
private void runTest_superordinateDomain(DateTime domainTransferTime, private void runTest_superordinateDomain(
@Nullable DateTime lastSuperordinateChange) throws Exception { DateTime domainTransferTime, @Nullable DateTime lastSuperordinateChange) throws Exception {
DomainResource domain = persistResource( DomainResource domain =
newDomainResource("parent.foobar").asBuilder() persistResource(
newDomainResource("parent.foobar")
.asBuilder()
.setRepoId("BEEF-FOOBAR") .setRepoId("BEEF-FOOBAR")
.setLastTransferTime(domainTransferTime) .setLastTransferTime(domainTransferTime)
.setPersistedCurrentSponsorClientId("superclientid") .setPersistedCurrentSponsorClientId("superclientid")
.build()); .build());
persistResource( persistResource(
persistHostResource().asBuilder() persistHostResource()
.asBuilder()
.setRepoId("CEEF-FOOBAR") .setRepoId("CEEF-FOOBAR")
.setSuperordinateDomain(Key.create(domain)) .setSuperordinateDomain(Key.create(domain))
.setLastSuperordinateChange(lastSuperordinateChange) .setLastSuperordinateChange(lastSuperordinateChange)
@ -126,17 +131,15 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
} }
@Test @Test
public void testSuccess_withSuperordinateDomain_hostMovedAfterDomainTransfer() public void testSuccess_withSuperordinateDomain_hostMovedAfterDomainTransfer() throws Exception {
throws Exception { runTest_superordinateDomain(
runTest_superordinateDomain(DateTime.parse("2000-01-08T09:00:00.0Z"), DateTime.parse("2000-01-08T09:00:00.0Z"), DateTime.parse("2000-03-01T01:00:00.0Z"));
DateTime.parse("2000-03-01T01:00:00.0Z"));
} }
@Test @Test
public void testSuccess_withSuperordinateDomain_hostMovedBeforeDomainTransfer() public void testSuccess_withSuperordinateDomain_hostMovedBeforeDomainTransfer() throws Exception {
throws Exception { runTest_superordinateDomain(
runTest_superordinateDomain(DateTime.parse("2000-04-08T09:00:00.0Z"), DateTime.parse("2000-04-08T09:00:00.0Z"), DateTime.parse("2000-02-08T09:00:00.0Z"));
DateTime.parse("2000-02-08T09:00:00.0Z"));
} }
@Test @Test
@ -163,7 +166,8 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
@Test @Test
public void testFailure_nonLowerCaseHostname() throws Exception { public void testFailure_nonLowerCaseHostname() throws Exception {
setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "NS1.EXAMPLE.NET")); setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "NS1.EXAMPLE.NET"));
assertThrows(HostNameNotLowerCaseException.class, this::runFlow); EppException thrown = expectThrows(HostNameNotLowerCaseException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test
@ -177,7 +181,8 @@ public class HostInfoFlowTest extends ResourceFlowTestCase<HostInfoFlow, HostRes
@Test @Test
public void testFailure_nonCanonicalHostname() throws Exception { public void testFailure_nonCanonicalHostname() throws Exception {
setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld.")); setEppInput("host_info.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld."));
assertThrows(HostNameNotNormalizedException.class, this::runFlow); EppException thrown = expectThrows(HostNameNotNormalizedException.class, this::runFlow);
assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @Test

File diff suppressed because it is too large Load diff