From 876552f1ce80e07ba880ba932c0680d073f74420 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Fri, 28 Apr 2017 12:33:17 -0700 Subject: [PATCH] Add more EPP metric lifecycle tests This also refactors some of the existing EPP XML testdata files to use a consistent wildcard naming scheme. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=154569632 --- .../flows/EppLifecycleContactTest.java | 52 +++++++++++++-- .../EppLifecycleDomainApplicationTest.java | 10 ++- .../flows/EppLifecycleDomainTest.java | 42 ++++++++---- .../registry/flows/EppLifecycleHostTest.java | 65 +++++++++++++++++++ .../registry/flows/testdata/host_create.xml | 2 +- .../registry/flows/testdata/host_create2.xml | 10 --- .../flows/testdata/host_create2_response.xml | 17 ----- .../flows/testdata/host_create_response.xml | 6 +- .../registry/flows/testdata/host_delete.xml | 11 ++++ .../registry/flows/testdata/host_info.xml | 2 +- .../flows/testdata/host_info_response.xml | 22 +++++++ ...t_info_response_fakesite_post_transfer.xml | 2 +- ...onse_fakesite_post_transfer_and_update.xml | 4 +- ..._post_transfer_and_update_no_addresses.xml | 4 +- .../registry/testing/EppMetricSubject.java | 7 ++ 15 files changed, 200 insertions(+), 56 deletions(-) delete mode 100644 javatests/google/registry/flows/testdata/host_create2.xml delete mode 100644 javatests/google/registry/flows/testdata/host_create2_response.xml create mode 100644 javatests/google/registry/flows/testdata/host_delete.xml create mode 100644 javatests/google/registry/flows/testdata/host_info_response.xml diff --git a/javatests/google/registry/flows/EppLifecycleContactTest.java b/javatests/google/registry/flows/EppLifecycleContactTest.java index 971d1ba3d..f23e94a5d 100644 --- a/javatests/google/registry/flows/EppLifecycleContactTest.java +++ b/javatests/google/registry/flows/EppLifecycleContactTest.java @@ -14,6 +14,12 @@ package google.registry.flows; +import static google.registry.model.eppoutput.Result.Code.SUCCESS; +import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACK_MESSAGE; +import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING; +import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_NO_MESSAGES; +import static google.registry.testing.EppMetricSubject.assertThat; + import com.google.common.collect.ImmutableMap; import google.registry.testing.AppEngineRule; import org.joda.time.DateTime; @@ -41,11 +47,35 @@ public class EppLifecycleContactTest extends EppTestCase { "contact_create_response_sh8013.xml", ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"), DateTime.parse("2000-06-01T00:00:00Z")); + assertThat(getRecordedEppMetric()) + .hasClientId("NewRegistrar") + .and() + .hasCommandName("ContactCreate") + .and() + .hasEppTarget("sh8013") + .and() + .hasStatus(SUCCESS); assertCommandAndResponse( "contact_info.xml", "contact_info_from_create_response.xml", DateTime.parse("2000-06-01T00:01:00Z")); + assertThat(getRecordedEppMetric()) + .hasClientId("NewRegistrar") + .and() + .hasCommandName("ContactInfo") + .and() + .hasEppTarget("sh8013") + .and() + .hasStatus(SUCCESS); assertCommandAndResponse("contact_delete_sh8013.xml", "contact_delete_response_sh8013.xml"); + assertThat(getRecordedEppMetric()) + .hasClientId("NewRegistrar") + .and() + .hasCommandName("ContactDelete") + .and() + .hasEppTarget("sh8013") + .and() + .hasStatus(SUCCESS_WITH_ACTION_PENDING); assertCommandAndResponse("logout.xml", "logout_response.xml"); } @@ -53,11 +83,11 @@ public class EppLifecycleContactTest extends EppTestCase { public void testContactTransferPollMessage() throws Exception { assertCommandAndResponse("login_valid.xml", "login_response.xml"); assertCommandAndResponse( - "contact_create_sh8013.xml", - ImmutableMap.of(), - "contact_create_response_sh8013.xml", - ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"), - DateTime.parse("2000-06-01T00:00:00Z")); + "contact_create_sh8013.xml", + ImmutableMap.of(), + "contact_create_response_sh8013.xml", + ImmutableMap.of("CRDATE", "2000-06-01T00:00:00Z"), + DateTime.parse("2000-06-01T00:00:00Z")); assertCommandAndResponse("logout.xml", "logout_response.xml"); // Initiate a transfer of the newly created contact. @@ -74,12 +104,24 @@ public class EppLifecycleContactTest extends EppTestCase { "poll.xml", "poll_response_contact_transfer.xml", DateTime.parse("2000-06-08T22:01:00Z")); + assertThat(getRecordedEppMetric()) + .hasClientId("NewRegistrar") + .and() + .hasCommandName("PollRequest") + .and() + .hasStatus(SUCCESS_WITH_ACK_MESSAGE); assertCommandAndResponse( "poll_ack.xml", ImmutableMap.of("ID", "2-1-ROID-3-6"), "poll_ack_response_empty.xml", null, DateTime.parse("2000-06-08T22:02:00Z")); + assertThat(getRecordedEppMetric()) + .hasClientId("NewRegistrar") + .and() + .hasCommandName("PollAck") + .and() + .hasStatus(SUCCESS_WITH_NO_MESSAGES); assertCommandAndResponse("logout.xml", "logout_response.xml"); } } diff --git a/javatests/google/registry/flows/EppLifecycleDomainApplicationTest.java b/javatests/google/registry/flows/EppLifecycleDomainApplicationTest.java index f1a75c781..d227d4cc2 100644 --- a/javatests/google/registry/flows/EppLifecycleDomainApplicationTest.java +++ b/javatests/google/registry/flows/EppLifecycleDomainApplicationTest.java @@ -62,11 +62,17 @@ public class EppLifecycleDomainApplicationTest extends EppTestCase { startTime.plusMinutes(1)); assertCommandAndResponse( "host_create.xml", + ImmutableMap.of("HOSTNAME", "ns1.example.external"), "host_create_response.xml", + ImmutableMap.of( + "HOSTNAME", "ns1.example.external", "CRDATE", startTime.plusMinutes(2).toString()), startTime.plusMinutes(2)); assertCommandAndResponse( - "host_create2.xml", - "host_create2_response.xml", + "host_create.xml", + ImmutableMap.of("HOSTNAME", "ns2.example.external"), + "host_create_response.xml", + ImmutableMap.of( + "HOSTNAME", "ns2.example.external", "CRDATE", startTime.plusMinutes(3).toString()), startTime.plusMinutes(3)); } diff --git a/javatests/google/registry/flows/EppLifecycleDomainTest.java b/javatests/google/registry/flows/EppLifecycleDomainTest.java index a226f0b49..c25a17e61 100644 --- a/javatests/google/registry/flows/EppLifecycleDomainTest.java +++ b/javatests/google/registry/flows/EppLifecycleDomainTest.java @@ -62,9 +62,19 @@ public class EppLifecycleDomainTest extends EppTestCase { "contact_create_response_jd1234.xml", startTime.plusMinutes(1)); assertCommandAndResponse( - "host_create.xml", "host_create_response.xml", startTime.plusMinutes(2)); + "host_create.xml", + ImmutableMap.of("HOSTNAME", "ns1.example.external"), + "host_create_response.xml", + ImmutableMap.of( + "HOSTNAME", "ns1.example.external", "CRDATE", startTime.plusMinutes(2).toString()), + startTime.plusMinutes(2)); assertCommandAndResponse( - "host_create2.xml", "host_create2_response.xml", startTime.plusMinutes(3)); + "host_create.xml", + ImmutableMap.of("HOSTNAME", "ns2.example.external"), + "host_create_response.xml", + ImmutableMap.of( + "HOSTNAME", "ns2.example.external", "CRDATE", startTime.plusMinutes(3).toString()), + startTime.plusMinutes(3)); } /** Creates the domain fakesite.example with two nameservers on it. */ @@ -336,6 +346,14 @@ public class EppLifecycleDomainTest extends EppTestCase { "domain_check_fee_premium.xml", "domain_check_fee_premium_response.xml", gaDate.plusDays(1)); + assertThat(getRecordedEppMetric()) + .hasClientId("NewRegistrar") + .and() + .hasCommandName("DomainCheck") + .and() + .hasEppTarget("rich.example") + .and() + .hasStatus(SUCCESS); assertCommandAndResponse("logout.xml", "logout_response.xml"); } @@ -481,7 +499,7 @@ public class EppLifecycleDomainTest extends EppTestCase { "host_info_fakesite.xml", null, "host_info_response_fakesite_post_transfer.xml", - ImmutableMap.of("trDate", "2002-06-04T00:00:00Z"), + ImmutableMap.of("TRDATE", "2002-06-04T00:00:00Z"), DateTime.parse("2002-06-09T00:01:00Z")); assertCommandAndResponse("logout.xml", "logout_response.xml"); } @@ -589,9 +607,9 @@ public class EppLifecycleDomainTest extends EppTestCase { // Verify that the lastTransferTime now reflects the superordinate domain's transfer. assertCommandAndResponse( "host_info.xml", - ImmutableMap.of("hostname", "ns3.fakesite.example"), + ImmutableMap.of("HOSTNAME", "ns3.fakesite.example"), "host_info_response_fakesite_post_transfer.xml", - ImmutableMap.of("trDate", "2001-01-06T00:00:00.000Z"), + ImmutableMap.of("TRDATE", "2001-01-06T00:00:00.000Z"), DateTime.parse("2001-01-07T00:00:00Z")); assertCommandAndResponse( "domain_create_secondsite.xml", @@ -608,11 +626,11 @@ public class EppLifecycleDomainTest extends EppTestCase { // The last transfer time on the host should still be what it was from the transfer. assertCommandAndResponse( "host_info.xml", - ImmutableMap.of("hostname", "ns3.secondsite.example"), + ImmutableMap.of("HOSTNAME", "ns3.secondsite.example"), "host_info_response_fakesite_post_transfer_and_update.xml", ImmutableMap.of( - "hostname", "ns3.secondsite.example", - "trDate", "2001-01-06T00:00:00.000Z"), + "HOSTNAME", "ns3.secondsite.example", + "TRDATE", "2001-01-06T00:00:00.000Z"), DateTime.parse("2003-01-07T00:00:00Z")); assertCommandAndResponse("logout.xml", "logout_response.xml"); } @@ -644,7 +662,7 @@ public class EppLifecycleDomainTest extends EppTestCase { "host_info_fakesite.xml", null, "host_info_response_fakesite_post_transfer.xml", - ImmutableMap.of("trDate", "2001-01-06T00:00:00.000Z"), + ImmutableMap.of("TRDATE", "2001-01-06T00:00:00.000Z"), DateTime.parse("2001-01-07T00:00:00Z")); // Update the host to be external by renaming it to ns3.notarealsite.external assertCommandAndResponse( @@ -658,11 +676,11 @@ public class EppLifecycleDomainTest extends EppTestCase { // The last transfer time on the host should still be what it was from the transfer. assertCommandAndResponse( "host_info.xml", - ImmutableMap.of("hostname", "ns3.notarealsite.external"), + ImmutableMap.of("HOSTNAME", "ns3.notarealsite.external"), "host_info_response_fakesite_post_transfer_and_update_no_addresses.xml", ImmutableMap.of( - "hostname", "ns3.notarealsite.external", - "trDate", "2001-01-06T00:00:00.000Z"), + "HOSTNAME", "ns3.notarealsite.external", + "TRDATE", "2001-01-06T00:00:00.000Z"), DateTime.parse("2001-01-07T00:00:00Z")); assertCommandAndResponse("logout.xml", "logout_response.xml"); } diff --git a/javatests/google/registry/flows/EppLifecycleHostTest.java b/javatests/google/registry/flows/EppLifecycleHostTest.java index fb8a5a414..cc3d20f12 100644 --- a/javatests/google/registry/flows/EppLifecycleHostTest.java +++ b/javatests/google/registry/flows/EppLifecycleHostTest.java @@ -14,7 +14,10 @@ package google.registry.flows; +import static google.registry.model.eppoutput.Result.Code.SUCCESS; +import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING; import static google.registry.testing.DatastoreHelper.createTld; +import static google.registry.testing.EppMetricSubject.assertThat; import com.google.common.collect.ImmutableMap; import google.registry.testing.AppEngineRule; @@ -34,6 +37,68 @@ public class EppLifecycleHostTest extends EppTestCase { .withTaskQueue() .build(); + @Test + public void testLifecycle() throws Exception { + assertCommandAndResponse("login_valid.xml", "login_response.xml"); + assertCommandAndResponse( + "hello.xml", + ImmutableMap.of(), + "greeting.xml", + ImmutableMap.of("DATE", "2000-06-02T00:00:00Z"), + DateTime.parse("2000-06-02T00:00:00Z")); + // Note that Hello commands don't set a status code on the response. + assertThat(getRecordedEppMetric()) + .hasClientId("NewRegistrar") + .and() + .hasCommandName("Hello") + .and() + .hasNoStatus(); + assertCommandAndResponse( + "host_create.xml", + ImmutableMap.of("HOSTNAME", "ns1.example.tld"), + "host_create_response.xml", + ImmutableMap.of("HOSTNAME", "ns1.example.tld", "CRDATE", "2000-06-02T00:01:00Z"), + DateTime.parse("2000-06-02T00:01:00Z")); + assertThat(getRecordedEppMetric()) + .hasClientId("NewRegistrar") + .and() + .hasCommandName("HostCreate") + .and() + .hasEppTarget("ns1.example.tld") + .and() + .hasStatus(SUCCESS); + assertCommandAndResponse( + "host_info.xml", + ImmutableMap.of("HOSTNAME", "ns1.example.tld"), + "host_info_response.xml", + ImmutableMap.of( + "HOSTNAME", "ns1.example.tld", "ROID", "1-ROID", "CRDATE", "2000-06-02T00:01:00Z"), + DateTime.parse("2000-06-02T00:02:00Z")); + assertThat(getRecordedEppMetric()) + .hasClientId("NewRegistrar") + .and() + .hasCommandName("HostInfo") + .and() + .hasEppTarget("ns1.example.tld") + .and() + .hasStatus(SUCCESS); + assertCommandAndResponse( + "host_delete.xml", + ImmutableMap.of("HOSTNAME", "ns1.example.tld"), + "generic_success_action_pending_response.xml", + ImmutableMap.of(), + DateTime.parse("2000-06-02T00:03:00Z")); + assertThat(getRecordedEppMetric()) + .hasClientId("NewRegistrar") + .and() + .hasCommandName("HostDelete") + .and() + .hasEppTarget("ns1.example.tld") + .and() + .hasStatus(SUCCESS_WITH_ACTION_PENDING); + assertCommandAndResponse("logout.xml", "logout_response.xml"); + } + @Test public void testRenamingHostToExistingHost_fails() throws Exception { createTld("example"); diff --git a/javatests/google/registry/flows/testdata/host_create.xml b/javatests/google/registry/flows/testdata/host_create.xml index 1ab7891c3..3e0a263ac 100644 --- a/javatests/google/registry/flows/testdata/host_create.xml +++ b/javatests/google/registry/flows/testdata/host_create.xml @@ -2,7 +2,7 @@ - ns1.example.external + %HOSTNAME% ABC-12345 diff --git a/javatests/google/registry/flows/testdata/host_create2.xml b/javatests/google/registry/flows/testdata/host_create2.xml deleted file mode 100644 index 12fdb2861..000000000 --- a/javatests/google/registry/flows/testdata/host_create2.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - ns2.example.external - - - ABC-12345 - - diff --git a/javatests/google/registry/flows/testdata/host_create2_response.xml b/javatests/google/registry/flows/testdata/host_create2_response.xml deleted file mode 100644 index cf1f5ecb9..000000000 --- a/javatests/google/registry/flows/testdata/host_create2_response.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - Command completed successfully - - - - ns2.example.external - 2000-06-01T00:03:00Z - - - - ABC-12345 - 54322-XYZ - - - diff --git a/javatests/google/registry/flows/testdata/host_create_response.xml b/javatests/google/registry/flows/testdata/host_create_response.xml index bbc019161..765c4b249 100644 --- a/javatests/google/registry/flows/testdata/host_create_response.xml +++ b/javatests/google/registry/flows/testdata/host_create_response.xml @@ -5,13 +5,13 @@ - ns1.example.external - 2000-06-01T00:02:00Z + %HOSTNAME% + %CRDATE% ABC-12345 - 54322-XYZ + server-trid diff --git a/javatests/google/registry/flows/testdata/host_delete.xml b/javatests/google/registry/flows/testdata/host_delete.xml new file mode 100644 index 000000000..57fc3f62a --- /dev/null +++ b/javatests/google/registry/flows/testdata/host_delete.xml @@ -0,0 +1,11 @@ + + + + + %HOSTNAME% + + + ABC-12345 + + diff --git a/javatests/google/registry/flows/testdata/host_info.xml b/javatests/google/registry/flows/testdata/host_info.xml index 515534c4e..e501434ee 100644 --- a/javatests/google/registry/flows/testdata/host_info.xml +++ b/javatests/google/registry/flows/testdata/host_info.xml @@ -2,7 +2,7 @@ - %hostname% + %HOSTNAME% ABC-12345 diff --git a/javatests/google/registry/flows/testdata/host_info_response.xml b/javatests/google/registry/flows/testdata/host_info_response.xml new file mode 100644 index 000000000..a6ac1b616 --- /dev/null +++ b/javatests/google/registry/flows/testdata/host_info_response.xml @@ -0,0 +1,22 @@ + + + + Command completed successfully + + + + %HOSTNAME% + %ROID% + + NewRegistrar + NewRegistrar + %CRDATE% + + + + ABC-12345 + server-trid + + + diff --git a/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer.xml b/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer.xml index 4c28341db..91ebc7ec9 100644 --- a/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer.xml +++ b/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer.xml @@ -16,7 +16,7 @@ TheRegistrar NewRegistrar 2000-06-06T00:01:00Z - %trDate% + %TRDATE% diff --git a/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer_and_update.xml b/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer_and_update.xml index b6c218cf4..9025a775d 100644 --- a/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer_and_update.xml +++ b/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer_and_update.xml @@ -6,7 +6,7 @@ - %hostname% + %HOSTNAME% NS1_EXAMPLE1-REP @@ -18,7 +18,7 @@ 2000-06-06T00:01:00Z TheRegistrar 2002-05-30T01:01:00Z - %trDate% + %TRDATE% diff --git a/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer_and_update_no_addresses.xml b/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer_and_update_no_addresses.xml index f160eb5a6..be2efbfed 100644 --- a/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer_and_update_no_addresses.xml +++ b/javatests/google/registry/flows/testdata/host_info_response_fakesite_post_transfer_and_update_no_addresses.xml @@ -6,7 +6,7 @@ - %hostname% + %HOSTNAME% NS1_EXAMPLE1-REP @@ -15,7 +15,7 @@ 2000-06-06T00:01:00Z TheRegistrar 2002-05-30T01:01:00Z - %trDate% + %TRDATE% diff --git a/javatests/google/registry/testing/EppMetricSubject.java b/javatests/google/registry/testing/EppMetricSubject.java index e937d8439..36ea95ebd 100644 --- a/javatests/google/registry/testing/EppMetricSubject.java +++ b/javatests/google/registry/testing/EppMetricSubject.java @@ -54,6 +54,13 @@ public class EppMetricSubject extends Subject { return hasValue(status, actual().getStatus(), "has status"); } + public And hasNoStatus() { + if (actual().getStatus().isPresent()) { + fail("has no status"); + } + return new And<>(this); + } + private And hasValue(E expected, Optional actual, String verb) { checkArgumentNotNull(expected, "Expected value cannot be null"); if (actual == null) {