Dagger, meet Flows. Flows, meet Dagger.

Daggerizes all of the EPP flows. This does not change anything yet
about the flows themselves, just how they are invoked, but after
this CL it's safe to @Inject things into flow classes.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=125382478
This commit is contained in:
cgoldfeder 2016-06-20 14:51:42 -07:00 committed by Ben McIlwain
parent 116bf1f4d6
commit c9a16f7f11
69 changed files with 973 additions and 292 deletions

View file

@ -15,35 +15,19 @@
package google.registry.model;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.picker.FlowPicker.getFlowClass;
import static google.registry.model.EppResourceUtils.loadAtPointInTime;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newHostResource;
import static google.registry.testing.DatastoreHelper.persistActiveContact;
import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DatastoreHelper.persistResourceWithCommitLog;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.time.DateTimeZone.UTC;
import static org.joda.time.Duration.standardDays;
import com.googlecode.objectify.Key;
import google.registry.flows.EppRequestSource;
import google.registry.flows.FlowRunner;
import google.registry.flows.HttpSessionMetadata;
import google.registry.flows.PasswordOnlyTransportCredentials;
import google.registry.flows.SessionMetadata;
import google.registry.model.domain.DomainResource;
import google.registry.model.eppcommon.Trid;
import google.registry.model.host.HostResource;
import google.registry.model.ofy.Ofy;
import google.registry.testing.AppEngineRule;
import google.registry.testing.EppLoader;
import google.registry.testing.ExceptionRule;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeHttpSession;
import google.registry.testing.InjectRule;
import org.joda.time.DateTime;
@ -71,7 +55,6 @@ public class EppResourceUtilsTest {
public final InjectRule inject = new InjectRule();
private final FakeClock clock = new FakeClock(DateTime.now(UTC));
private EppLoader eppLoader;
@Before
public void init() throws Exception {
@ -79,103 +62,6 @@ public class EppResourceUtilsTest {
inject.setStaticField(Ofy.class, "clock", clock);
}
private void runFlow() throws Exception {
SessionMetadata sessionMetadata = new HttpSessionMetadata(new FakeHttpSession());
sessionMetadata.setClientId("TheRegistrar");
new FlowRunner(
getFlowClass(eppLoader.getEpp()),
eppLoader.getEpp(),
Trid.create(null, "server-trid"),
sessionMetadata,
new PasswordOnlyTransportCredentials(),
EppRequestSource.UNIT_TEST,
false,
false,
"<xml></xml>".getBytes(),
null,
clock)
.run();
}
/** Test that update flow creates commit logs needed to reload at any arbitrary time. */
@Test
public void testLoadAtPointInTime() throws Exception {
clock.setTo(DateTime.parse("1984-12-18T12:30Z")); // not midnight
persistActiveHost("ns1.example.net");
persistActiveHost("ns2.example.net");
persistActiveContact("jd1234");
persistActiveContact("sh8013");
clock.advanceBy(standardDays(1));
DateTime timeAtCreate = clock.nowUtc();
clock.setTo(timeAtCreate);
eppLoader = new EppLoader(this, "domain_create.xml");
runFlow();
ofy().clearSessionCache();
Key<DomainResource> key = Key.create(ofy().load().type(DomainResource.class).first().now());
DomainResource domainAfterCreate = ofy().load().key(key).now();
assertThat(domainAfterCreate.getFullyQualifiedDomainName()).isEqualTo("example.tld");
clock.advanceBy(standardDays(2));
DateTime timeAtFirstUpdate = clock.nowUtc();
eppLoader = new EppLoader(this, "domain_update_dsdata_add.xml");
runFlow();
ofy().clearSessionCache();
DomainResource domainAfterFirstUpdate = ofy().load().key(key).now();
assertThat(domainAfterCreate).isNotEqualTo(domainAfterFirstUpdate);
clock.advanceOneMilli(); // same day as first update
DateTime timeAtSecondUpdate = clock.nowUtc();
eppLoader = new EppLoader(this, "domain_update_dsdata_rem.xml");
runFlow();
ofy().clearSessionCache();
DomainResource domainAfterSecondUpdate = ofy().load().key(key).now();
clock.advanceBy(standardDays(2));
DateTime timeAtDelete = clock.nowUtc(); // before 'add' grace period ends
eppLoader = new EppLoader(this, "domain_delete.xml");
runFlow();
ofy().clearSessionCache();
assertThat(domainAfterFirstUpdate).isNotEqualTo(domainAfterSecondUpdate);
// Point-in-time can only rewind an object from the current version, not roll forward.
DomainResource latest = ofy().load().key(key).now();
// Creation time has millisecond granularity due to isActive() check.
ofy().clearSessionCache();
assertThat(loadAtPointInTime(latest, timeAtCreate.minusMillis(1)).now()).isNull();
assertThat(loadAtPointInTime(latest, timeAtCreate).now()).isNotNull();
assertThat(loadAtPointInTime(latest, timeAtCreate.plusMillis(1)).now()).isNotNull();
ofy().clearSessionCache();
assertThat(loadAtPointInTime(latest, timeAtCreate.plusDays(1)).now())
.isEqualTo(domainAfterCreate);
// Both updates happened on the same day. Since the revisions field has day granularity, the
// reference to the first update should have been overwritten by the second, and its timestamp
// rolled forward. So we have to fall back to the last revision before midnight.
ofy().clearSessionCache();
assertThat(loadAtPointInTime(latest, timeAtFirstUpdate).now())
.isEqualTo(domainAfterCreate);
ofy().clearSessionCache();
assertThat(loadAtPointInTime(latest, timeAtSecondUpdate).now())
.isEqualTo(domainAfterSecondUpdate);
ofy().clearSessionCache();
assertThat(loadAtPointInTime(latest, timeAtSecondUpdate.plusDays(1)).now())
.isEqualTo(domainAfterSecondUpdate);
// Deletion time has millisecond granularity due to isActive() check.
ofy().clearSessionCache();
assertThat(loadAtPointInTime(latest, timeAtDelete.minusMillis(1)).now()).isNotNull();
assertThat(loadAtPointInTime(latest, timeAtDelete).now()).isNull();
assertThat(loadAtPointInTime(latest, timeAtDelete.plusMillis(1)).now()).isNull();
}
@Test
public void testLoadAtPointInTime_beforeCreated_returnsNull() throws Exception {
clock.advanceOneMilli();