From 3eff20ceb5b0eac0f466acefe16b3a0d6d4ed352 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Thu, 29 Nov 2018 10:08:40 -0800 Subject: [PATCH] Consolidate EPP lifecycle helper methods I'm adding another EPP lifecycle test that will need to be in the tools package because it has to call tools as part of the lifecycle. This commit consolidates common functionality within the EppTestCase abstract base class (and increases visibility) so that it can easily be referenced by more extending classes, even ones in a different package. This also explicitly loads the test files from the testdata directory collocated with EppTestCase, so that new tests in other packages won't have to duplicate lots of these same test files. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=223365398 --- .../EppLifecycleDomainApplicationTest.java | 25 ----- .../flows/EppLifecycleDomainTest.java | 68 -------------- .../google/registry/flows/EppTestCase.java | 94 ++++++++++++++++--- 3 files changed, 81 insertions(+), 106 deletions(-) diff --git a/javatests/google/registry/flows/EppLifecycleDomainApplicationTest.java b/javatests/google/registry/flows/EppLifecycleDomainApplicationTest.java index b9e043ab9..bb9fb2d0a 100644 --- a/javatests/google/registry/flows/EppLifecycleDomainApplicationTest.java +++ b/javatests/google/registry/flows/EppLifecycleDomainApplicationTest.java @@ -47,31 +47,6 @@ public class EppLifecycleDomainApplicationTest extends EppTestCase { START_OF_GA, TldState.GENERAL_AVAILABILITY)); } - /** Create the two administrative contacts and two hosts. */ - void createContactsAndHosts() throws Exception { - DateTime startTime = DateTime.parse("2000-06-01T00:00:00Z"); - assertThatCommand("contact_create_sh8013.xml") - .atTime(startTime) - .hasResponse( - "contact_create_response_sh8013.xml", - ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z")); - assertThatCommand("contact_create_jd1234.xml") - .atTime(startTime.plusMinutes(1)) - .hasResponse("contact_create_response_jd1234.xml"); - assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns1.example.external")) - .atTime(startTime.plusMinutes(2)) - .hasResponse( - "host_create_response.xml", - ImmutableMap.of( - "HOSTNAME", "ns1.example.external", "CRDATE", startTime.plusMinutes(2).toString())); - assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns2.example.external")) - .atTime(startTime.plusMinutes(3)) - .hasResponse( - "host_create_response.xml", - ImmutableMap.of( - "HOSTNAME", "ns2.example.external", "CRDATE", startTime.plusMinutes(3).toString())); - } - @Test public void testApplicationDuringSunrise_doesntCreateDomainWithoutAllocation() throws Exception { assertThatLoginSucceeds("NewRegistrar", "foo-BAR2"); diff --git a/javatests/google/registry/flows/EppLifecycleDomainTest.java b/javatests/google/registry/flows/EppLifecycleDomainTest.java index edd705e77..4af7aa03c 100644 --- a/javatests/google/registry/flows/EppLifecycleDomainTest.java +++ b/javatests/google/registry/flows/EppLifecycleDomainTest.java @@ -68,74 +68,6 @@ public class EppLifecycleDomainTest extends EppTestCase { createTlds("example", "tld"); } - /** Create the two administrative contacts and two hosts. */ - void createContactsAndHosts() throws Exception { - DateTime createTime = DateTime.parse("2000-06-01T00:00:00Z"); - createContacts(createTime); - assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns1.example.external")) - .atTime(createTime.plusMinutes(2)) - .hasResponse( - "host_create_response.xml", - ImmutableMap.of( - "HOSTNAME", "ns1.example.external", - "CRDATE", createTime.plusMinutes(2).toString())); - assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns2.example.external")) - .atTime(createTime.plusMinutes(3)) - .hasResponse( - "host_create_response.xml", - ImmutableMap.of( - "HOSTNAME", "ns2.example.external", - "CRDATE", createTime.plusMinutes(3).toString())); - } - - private void createContacts(DateTime createTime) throws Exception { - assertThatCommand("contact_create_sh8013.xml") - .atTime(createTime) - .hasResponse( - "contact_create_response_sh8013.xml", ImmutableMap.of("CRDATE", createTime.toString())); - assertThatCommand("contact_create_jd1234.xml") - .atTime(createTime.plusMinutes(1)) - .hasResponse( - "contact_create_response_jd1234.xml", - ImmutableMap.of("CRDATE", createTime.plusMinutes(1).toString())); - } - - /** Creates the domain fakesite.example with two nameservers on it. */ - void createFakesite() throws Exception { - createContactsAndHosts(); - assertThatCommand("domain_create_fakesite.xml") - .atTime("2000-06-01T00:04:00Z") - .hasResponse( - "domain_create_response.xml", - ImmutableMap.of( - "DOMAIN", "fakesite.example", - "CRDATE", "2000-06-01T00:04:00.0Z", - "EXDATE", "2002-06-01T00:04:00.0Z")); - assertThatCommand("domain_info_fakesite.xml") - .atTime("2000-06-06T00:00:00Z") - .hasResponse("domain_info_response_fakesite_ok.xml"); - } - - /** Creates ns3.fakesite.example as a host, then adds it to fakesite. */ - void createSubordinateHost() throws Exception { - // Add the fakesite nameserver (requires that domain is already created). - assertThatCommand("host_create_fakesite.xml") - .atTime("2000-06-06T00:01:00Z") - .hasResponse("host_create_response_fakesite.xml"); - // Add new nameserver to domain. - assertThatCommand("domain_update_add_nameserver_fakesite.xml") - .atTime("2000-06-08T00:00:00Z") - .hasResponse("generic_success_response.xml"); - // Verify new nameserver was added. - assertThatCommand("domain_info_fakesite.xml") - .atTime("2000-06-08T00:01:00Z") - .hasResponse("domain_info_response_fakesite_3_nameservers.xml"); - // Verify that nameserver's data was set correctly. - assertThatCommand("host_info_fakesite.xml") - .atTime("2000-06-08T00:02:00Z") - .hasResponse("host_info_response_fakesite_linked.xml"); - } - @Test public void testDomainDeleteRestore() throws Exception { assertThatLoginSucceeds("NewRegistrar", "foo-BAR2"); diff --git a/javatests/google/registry/flows/EppTestCase.java b/javatests/google/registry/flows/EppTestCase.java index 86b0001d1..9a77c80d4 100644 --- a/javatests/google/registry/flows/EppTestCase.java +++ b/javatests/google/registry/flows/EppTestCase.java @@ -75,7 +75,7 @@ public class EppTestCase extends ShardableTestCase { this.isSuperuser = isSuperuser; } - class CommandAsserter { + public class CommandAsserter { private final String inputFilename; private @Nullable final Map inputSubstitutions; private DateTime now; @@ -87,44 +87,44 @@ public class EppTestCase extends ShardableTestCase { this.now = DateTime.now(UTC); } - CommandAsserter atTime(DateTime now) { + public CommandAsserter atTime(DateTime now) { this.now = now; return this; } - CommandAsserter atTime(String now) { + public CommandAsserter atTime(String now) { return atTime(DateTime.parse(now)); } - String hasResponse(String outputFilename) throws Exception { + public String hasResponse(String outputFilename) throws Exception { return hasResponse(outputFilename, null); } - String hasResponse(String outputFilename, @Nullable Map outputSubstitutions) - throws Exception { + public String hasResponse( + String outputFilename, @Nullable Map outputSubstitutions) throws Exception { return assertCommandAndResponse( inputFilename, inputSubstitutions, outputFilename, outputSubstitutions, now); } } - CommandAsserter assertThatCommand(String inputFilename) { + protected CommandAsserter assertThatCommand(String inputFilename) { return assertThatCommand(inputFilename, null); } - CommandAsserter assertThatCommand( + protected CommandAsserter assertThatCommand( String inputFilename, @Nullable Map inputSubstitutions) { return new CommandAsserter(inputFilename, inputSubstitutions); } - CommandAsserter assertThatLogin(String clientId, String password) { + protected CommandAsserter assertThatLogin(String clientId, String password) { return assertThatCommand("login.xml", ImmutableMap.of("CLID", clientId, "PW", password)); } - void assertThatLoginSucceeds(String clientId, String password) throws Exception { + protected void assertThatLoginSucceeds(String clientId, String password) throws Exception { assertThatLogin(clientId, password).hasResponse("generic_success_response.xml"); } - void assertThatLogoutSucceeds() throws Exception { + protected void assertThatLogoutSucceeds() throws Exception { assertThatCommand("logout.xml").hasResponse("logout_response.xml"); } @@ -136,8 +136,8 @@ public class EppTestCase extends ShardableTestCase { DateTime now) throws Exception { clock.setTo(now); - String input = loadFile(getClass(), inputFilename, inputSubstitutions); - String expectedOutput = loadFile(getClass(), outputFilename, outputSubstitutions); + String input = loadFile(EppTestCase.class, inputFilename, inputSubstitutions); + String expectedOutput = loadFile(EppTestCase.class, outputFilename, outputSubstitutions); if (sessionMetadata == null) { sessionMetadata = new HttpSessionMetadata(new FakeHttpSession()) { @@ -188,4 +188,72 @@ public class EppTestCase extends ShardableTestCase { protected EppMetric getRecordedEppMetric() { return eppMetricBuilder.build(); } + + /** Create the two administrative contacts and two hosts. */ + protected void createContactsAndHosts() throws Exception { + DateTime createTime = DateTime.parse("2000-06-01T00:00:00Z"); + createContacts(createTime); + assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns1.example.external")) + .atTime(createTime.plusMinutes(2)) + .hasResponse( + "host_create_response.xml", + ImmutableMap.of( + "HOSTNAME", "ns1.example.external", + "CRDATE", createTime.plusMinutes(2).toString())); + assertThatCommand("host_create.xml", ImmutableMap.of("HOSTNAME", "ns2.example.external")) + .atTime(createTime.plusMinutes(3)) + .hasResponse( + "host_create_response.xml", + ImmutableMap.of( + "HOSTNAME", "ns2.example.external", + "CRDATE", createTime.plusMinutes(3).toString())); + } + + protected void createContacts(DateTime createTime) throws Exception { + assertThatCommand("contact_create_sh8013.xml") + .atTime(createTime) + .hasResponse( + "contact_create_response_sh8013.xml", ImmutableMap.of("CRDATE", createTime.toString())); + assertThatCommand("contact_create_jd1234.xml") + .atTime(createTime.plusMinutes(1)) + .hasResponse( + "contact_create_response_jd1234.xml", + ImmutableMap.of("CRDATE", createTime.plusMinutes(1).toString())); + } + + /** Creates the domain fakesite.example with two nameservers on it. */ + protected void createFakesite() throws Exception { + createContactsAndHosts(); + assertThatCommand("domain_create_fakesite.xml") + .atTime("2000-06-01T00:04:00Z") + .hasResponse( + "domain_create_response.xml", + ImmutableMap.of( + "DOMAIN", "fakesite.example", + "CRDATE", "2000-06-01T00:04:00.0Z", + "EXDATE", "2002-06-01T00:04:00.0Z")); + assertThatCommand("domain_info_fakesite.xml") + .atTime("2000-06-06T00:00:00Z") + .hasResponse("domain_info_response_fakesite_ok.xml"); + } + + /** Creates ns3.fakesite.example as a host, then adds it to fakesite. */ + protected void createSubordinateHost() throws Exception { + // Add the fakesite nameserver (requires that domain is already created). + assertThatCommand("host_create_fakesite.xml") + .atTime("2000-06-06T00:01:00Z") + .hasResponse("host_create_response_fakesite.xml"); + // Add new nameserver to domain. + assertThatCommand("domain_update_add_nameserver_fakesite.xml") + .atTime("2000-06-08T00:00:00Z") + .hasResponse("generic_success_response.xml"); + // Verify new nameserver was added. + assertThatCommand("domain_info_fakesite.xml") + .atTime("2000-06-08T00:01:00Z") + .hasResponse("domain_info_response_fakesite_3_nameservers.xml"); + // Verify that nameserver's data was set correctly. + assertThatCommand("host_info_fakesite.xml") + .atTime("2000-06-08T00:02:00Z") + .hasResponse("host_info_response_fakesite_linked.xml"); + } }