Make Hello flows use the flow "now" time

This cleans up some of the tests, and helps with
future injection CLs.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=124208164
This commit is contained in:
Corey Goldfeder 2016-06-06 20:41:37 -07:00 committed by Justine Tunney
parent 81dc55ceab
commit 5a2f63cf58
7 changed files with 30 additions and 19 deletions

View file

@ -22,6 +22,6 @@ import google.registry.model.eppoutput.Greeting;
public class HelloFlow extends Flow { public class HelloFlow extends Flow {
@Override @Override
public EppOutput run() { public EppOutput run() {
return EppOutput.create(new Greeting()); return EppOutput.create(Greeting.create(now));
} }
} }

View file

@ -14,8 +14,6 @@
package google.registry.model.eppoutput; package google.registry.model.eppoutput;
import static org.joda.time.DateTimeZone.UTC;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.model.eppcommon.PresenceMarker; import google.registry.model.eppcommon.PresenceMarker;
import google.registry.model.eppcommon.ProtocolDefinition; import google.registry.model.eppcommon.ProtocolDefinition;
@ -37,7 +35,7 @@ import javax.xml.bind.annotation.XmlElementWrapper;
public class Greeting extends ImmutableObject implements ResponseOrGreeting { public class Greeting extends ImmutableObject implements ResponseOrGreeting {
String svID = "Charleston Road Registry"; String svID = "Charleston Road Registry";
DateTime svDate = DateTime.now(UTC); DateTime svDate;
/** This is never changed, so it might as well be static for efficiency. */ /** This is never changed, so it might as well be static for efficiency. */
@XmlElement @XmlElement
@ -47,6 +45,12 @@ public class Greeting extends ImmutableObject implements ResponseOrGreeting {
@XmlElement @XmlElement
static Dcp dcp = new Dcp(); static Dcp dcp = new Dcp();
public static Greeting create(DateTime svDate) {
Greeting instance = new Greeting();
instance.svDate = svDate;
return instance;
}
static class SvcMenu extends ImmutableObject { static class SvcMenu extends ImmutableObject {
String version = ProtocolDefinition.VERSION; String version = ProtocolDefinition.VERSION;
String lang = ProtocolDefinition.LANGUAGE; String lang = ProtocolDefinition.LANGUAGE;

View file

@ -16,8 +16,6 @@ package google.registry.flows;
import static google.registry.testing.DatastoreHelper.createTld; import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static google.registry.util.ResourceUtils.readResourceUtf8;
import static google.registry.xml.XmlTestUtils.assertXmlEquals;
import static org.joda.time.DateTimeZone.UTC; import static org.joda.time.DateTimeZone.UTC;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -27,6 +25,7 @@ import google.registry.model.registry.Registry.TldState;
import google.registry.util.DateTimeUtils; import google.registry.util.DateTimeUtils;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
import org.junit.Test; import org.junit.Test;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
@ -41,10 +40,13 @@ public abstract class EppServletXmlLoginTestCase<S extends HttpServlet> extends
@Test @Test
public void testHello() throws Exception { public void testHello() throws Exception {
assertXmlEquals( DateTime now = DateTime.now(UTC);
readResourceUtf8(getClass(), "testdata/greeting_crr.xml"), assertCommandAndResponse(
expectXmlCommand(readResourceUtf8(getClass(), "testdata/hello.xml"), DateTime.now(UTC)), "hello.xml",
"epp.greeting.svDate"); null,
"greeting_crr.xml",
ImmutableMap.of("DATE", now.toString(ISODateTimeFormat.dateTimeNoMillis())),
now);
} }
@Test @Test

View file

@ -288,7 +288,9 @@ public abstract class FlowTestCase<F extends Flow> {
CommitMode commitMode, UserPrivileges userPrivileges, String xml, String... ignoredPaths) CommitMode commitMode, UserPrivileges userPrivileges, String xml, String... ignoredPaths)
throws Exception { throws Exception {
EppOutput eppOutput = getFlowRunner().run(commitMode, userPrivileges); EppOutput eppOutput = getFlowRunner().run(commitMode, userPrivileges);
if (eppOutput.isResponse()) {
assertThat(eppOutput.isSuccess()).isTrue(); assertThat(eppOutput.isSuccess()).isTrue();
}
try { try {
assertXmlEquals( assertXmlEquals(
xml, new String(marshal(eppOutput, ValidationMode.STRICT), UTF_8), ignoredPaths); xml, new String(marshal(eppOutput, ValidationMode.STRICT), UTF_8), ignoredPaths);

View file

@ -14,10 +14,10 @@
package google.registry.flows.session; package google.registry.flows.session;
import static google.registry.flows.EppXmlTransformer.marshal; import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions;
import static google.registry.xml.ValidationMode.STRICT; import static org.joda.time.format.ISODateTimeFormat.dateTimeNoMillis;
import static google.registry.xml.XmlTestUtils.assertXmlEquals;
import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.collect.ImmutableMap;
import google.registry.flows.FlowTestCase; import google.registry.flows.FlowTestCase;
@ -29,8 +29,11 @@ public class HelloFlowTest extends FlowTestCase<HelloFlow> {
public void testHello() throws Exception { public void testHello() throws Exception {
setEppInput("hello.xml"); setEppInput("hello.xml");
assertTransactionalFlow(false); assertTransactionalFlow(false);
assertXmlEquals(readFile("greeting_crr.xml"), new String(marshal(runFlow(), STRICT), UTF_8), runFlowAssertResponse(
"epp.greeting.svDate"); loadFileWithSubstitutions(
getClass(),
"greeting_crr.xml",
ImmutableMap.of("DATE", clock.nowUtc().toString(dateTimeNoMillis()))));
} }
// Extra methods so the test runner doesn't produce empty shards. // Extra methods so the test runner doesn't produce empty shards.

View file

@ -1,7 +1,7 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<greeting> <greeting>
<svID>Charleston Road Registry</svID> <svID>Charleston Road Registry</svID>
<svDate>2000-06-08T22:00:00.0Z</svDate> <svDate>%DATE%</svDate>
<svcMenu> <svcMenu>
<version>1.0</version> <version>1.0</version>
<lang>en</lang> <lang>en</lang>

View file

@ -1,7 +1,7 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<greeting> <greeting>
<svID>Charleston Road Registry</svID> <svID>Charleston Road Registry</svID>
<svDate>2000-06-08T22:00:00.0Z</svDate> <svDate>%DATE%</svDate>
<svcMenu> <svcMenu>
<version>1.0</version> <version>1.0</version>
<lang>en</lang> <lang>en</lang>