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
This commit is contained in:
mcilwain 2018-11-29 10:08:40 -08:00 committed by jianglai
parent 849ea0e0f3
commit 3eff20ceb5
3 changed files with 81 additions and 106 deletions

View file

@ -47,31 +47,6 @@ public class EppLifecycleDomainApplicationTest extends EppTestCase {
START_OF_GA, TldState.GENERAL_AVAILABILITY)); 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 @Test
public void testApplicationDuringSunrise_doesntCreateDomainWithoutAllocation() throws Exception { public void testApplicationDuringSunrise_doesntCreateDomainWithoutAllocation() throws Exception {
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");

View file

@ -68,74 +68,6 @@ public class EppLifecycleDomainTest extends EppTestCase {
createTlds("example", "tld"); 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 @Test
public void testDomainDeleteRestore() throws Exception { public void testDomainDeleteRestore() throws Exception {
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2"); assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");

View file

@ -75,7 +75,7 @@ public class EppTestCase extends ShardableTestCase {
this.isSuperuser = isSuperuser; this.isSuperuser = isSuperuser;
} }
class CommandAsserter { public class CommandAsserter {
private final String inputFilename; private final String inputFilename;
private @Nullable final Map<String, String> inputSubstitutions; private @Nullable final Map<String, String> inputSubstitutions;
private DateTime now; private DateTime now;
@ -87,44 +87,44 @@ public class EppTestCase extends ShardableTestCase {
this.now = DateTime.now(UTC); this.now = DateTime.now(UTC);
} }
CommandAsserter atTime(DateTime now) { public CommandAsserter atTime(DateTime now) {
this.now = now; this.now = now;
return this; return this;
} }
CommandAsserter atTime(String now) { public CommandAsserter atTime(String now) {
return atTime(DateTime.parse(now)); return atTime(DateTime.parse(now));
} }
String hasResponse(String outputFilename) throws Exception { public String hasResponse(String outputFilename) throws Exception {
return hasResponse(outputFilename, null); return hasResponse(outputFilename, null);
} }
String hasResponse(String outputFilename, @Nullable Map<String, String> outputSubstitutions) public String hasResponse(
throws Exception { String outputFilename, @Nullable Map<String, String> outputSubstitutions) throws Exception {
return assertCommandAndResponse( return assertCommandAndResponse(
inputFilename, inputSubstitutions, outputFilename, outputSubstitutions, now); inputFilename, inputSubstitutions, outputFilename, outputSubstitutions, now);
} }
} }
CommandAsserter assertThatCommand(String inputFilename) { protected CommandAsserter assertThatCommand(String inputFilename) {
return assertThatCommand(inputFilename, null); return assertThatCommand(inputFilename, null);
} }
CommandAsserter assertThatCommand( protected CommandAsserter assertThatCommand(
String inputFilename, @Nullable Map<String, String> inputSubstitutions) { String inputFilename, @Nullable Map<String, String> inputSubstitutions) {
return new CommandAsserter(inputFilename, 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)); 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"); assertThatLogin(clientId, password).hasResponse("generic_success_response.xml");
} }
void assertThatLogoutSucceeds() throws Exception { protected void assertThatLogoutSucceeds() throws Exception {
assertThatCommand("logout.xml").hasResponse("logout_response.xml"); assertThatCommand("logout.xml").hasResponse("logout_response.xml");
} }
@ -136,8 +136,8 @@ public class EppTestCase extends ShardableTestCase {
DateTime now) DateTime now)
throws Exception { throws Exception {
clock.setTo(now); clock.setTo(now);
String input = loadFile(getClass(), inputFilename, inputSubstitutions); String input = loadFile(EppTestCase.class, inputFilename, inputSubstitutions);
String expectedOutput = loadFile(getClass(), outputFilename, outputSubstitutions); String expectedOutput = loadFile(EppTestCase.class, outputFilename, outputSubstitutions);
if (sessionMetadata == null) { if (sessionMetadata == null) {
sessionMetadata = sessionMetadata =
new HttpSessionMetadata(new FakeHttpSession()) { new HttpSessionMetadata(new FakeHttpSession()) {
@ -188,4 +188,72 @@ public class EppTestCase extends ShardableTestCase {
protected EppMetric getRecordedEppMetric() { protected EppMetric getRecordedEppMetric() {
return eppMetricBuilder.build(); 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");
}
} }