Add extra flow logic for Restore

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=137191080
This commit is contained in:
mountford 2016-10-25 12:58:40 -07:00 committed by Ben McIlwain
parent a4d78afd70
commit e40db46822
5 changed files with 38 additions and 11 deletions

View file

@ -27,7 +27,6 @@ import static google.registry.flows.domain.DomainFlowUtils.verifyPremiumNameIsNo
import static google.registry.model.domain.fee.Fee.FEE_UPDATE_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER; import static google.registry.model.domain.fee.Fee.FEE_UPDATE_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER;
import static google.registry.model.eppoutput.Result.Code.SUCCESS; import static google.registry.model.eppoutput.Result.Code.SUCCESS;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.base.Optional; import com.google.common.base.Optional;
@ -43,6 +42,7 @@ import google.registry.flows.FlowModule.ClientId;
import google.registry.flows.FlowModule.TargetId; import google.registry.flows.FlowModule.TargetId;
import google.registry.flows.LoggedInFlow; import google.registry.flows.LoggedInFlow;
import google.registry.flows.TransactionalFlow; import google.registry.flows.TransactionalFlow;
import google.registry.flows.domain.TldSpecificLogicProxy.EppCommandOperations;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.model.billing.BillingEvent; import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.OneTime; import google.registry.model.billing.BillingEvent.OneTime;
@ -122,13 +122,17 @@ public final class DomainRestoreRequestFlow extends LoggedInFlow implements Tran
Update command = (Update) resourceCommand; Update command = (Update) resourceCommand;
DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now); DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now);
Money restoreCost = Registry.get(existingDomain.getTld()).getStandardRestoreCost(); Money restoreCost = Registry.get(existingDomain.getTld()).getStandardRestoreCost();
Money renewCost = getDomainRenewCost(targetId, now, 1); EppCommandOperations renewCommandOperations = TldSpecificLogicProxy.getRenewPrice(
Registry.get(existingDomain.getTld()), targetId, clientId, now, 1, eppInput);
FeeTransformCommandExtension feeUpdate = eppInput.getFirstExtensionOfClasses( FeeTransformCommandExtension feeUpdate = eppInput.getFirstExtensionOfClasses(
FEE_UPDATE_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER); FEE_UPDATE_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER);
verifyRestoreAllowed(command, existingDomain, restoreCost, renewCost, feeUpdate); verifyRestoreAllowed(
command, existingDomain, restoreCost, renewCommandOperations.getTotalCost(), feeUpdate);
HistoryEntry historyEntry = buildHistory(existingDomain); HistoryEntry historyEntry = buildHistory(existingDomain);
ImmutableSet.Builder<ImmutableObject> entitiesToSave = new ImmutableSet.Builder<>(); ImmutableSet.Builder<ImmutableObject> entitiesToSave = new ImmutableSet.Builder<>();
entitiesToSave.addAll(createRestoreAndRenewBillingEvents(historyEntry, restoreCost, renewCost)); entitiesToSave.addAll(
createRestoreAndRenewBillingEvents(
historyEntry, restoreCost, renewCommandOperations.getTotalCost()));
// We don't preserve the original expiration time of the domain when we restore, since doing so // We don't preserve the original expiration time of the domain when we restore, since doing so
// would require us to know if they received a grace period refund when they deleted the domain, // would require us to know if they received a grace period refund when they deleted the domain,
// and to charge them for that again. Instead, we just say that all restores get a fresh year of // and to charge them for that again. Instead, we just say that all restores get a fresh year of
@ -159,7 +163,10 @@ public final class DomainRestoreRequestFlow extends LoggedInFlow implements Tran
ofy().save().entities(entitiesToSave.build()); ofy().save().entities(entitiesToSave.build());
ofy().delete().key(existingDomain.getDeletePollMessage()); ofy().delete().key(existingDomain.getDeletePollMessage());
dnsQueue.addDomainRefreshTask(existingDomain.getFullyQualifiedDomainName()); dnsQueue.addDomainRefreshTask(existingDomain.getFullyQualifiedDomainName());
return createOutput(SUCCESS, null, createResponseExtensions(restoreCost, renewCost, feeUpdate)); return createOutput(
SUCCESS,
null,
createResponseExtensions(restoreCost, renewCommandOperations.getTotalCost(), feeUpdate));
} }
private HistoryEntry buildHistory(DomainResource existingDomain) { private HistoryEntry buildHistory(DomainResource existingDomain) {

View file

@ -615,7 +615,8 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
@Test @Test
public void testFailure_flags_feeMismatch() throws Exception { public void testFailure_flags_feeMismatch() throws Exception {
setEppInput("domain_renew_flags.xml", ImmutableMap.of("FEE", "11")); setEppInput(
"domain_renew_flags.xml", ImmutableMap.of("DOMAIN", "renew-42.flags", "FEE", "11"));
persistDomain(); persistDomain();
thrown.expect(FeesMismatchException.class); thrown.expect(FeesMismatchException.class);
runFlow(); runFlow();
@ -623,7 +624,8 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
@Test @Test
public void testSuccess_flags() throws Exception { public void testSuccess_flags() throws Exception {
setEppInput("domain_renew_flags.xml", ImmutableMap.of("FEE", "42")); setEppInput(
"domain_renew_flags.xml", ImmutableMap.of("DOMAIN", "renew-42.flags", "FEE", "42"));
persistDomain(); persistDomain();
thrown.expect(TestExtraLogicManagerSuccessException.class, "renewed"); thrown.expect(TestExtraLogicManagerSuccessException.class, "renewed");
runFlow(); runFlow();

View file

@ -554,8 +554,22 @@ public class DomainRestoreRequestFlowTest extends
} }
@Test @Test
public void testSuccess_flags() throws Exception { public void testFlags_flagsWithWrongFee() throws Exception {
setEppInput("domain_update_restore_request_flags.xml"); setEppInput(
"domain_update_restore_request_flags.xml",
ImmutableMap.of("DOMAIN", "renew-42.flags", "FEE", "12"));
persistPendingDeleteDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
}
@Test
public void testSuccess_flagsWithCorrectFee() throws Exception {
// The total cost should be the renewal cost of 42 (set in the XML file) plus the restore cost
// of 17 (set in the test registry).
setEppInput(
"domain_update_restore_request_flags.xml",
ImmutableMap.of("DOMAIN", "renew-42.flags", "FEE", "59"));
persistPendingDeleteDomain(); persistPendingDeleteDomain();
thrown.expect(TestExtraLogicManagerSuccessException.class, "restored"); thrown.expect(TestExtraLogicManagerSuccessException.class, "restored");
runFlow(); runFlow();

View file

@ -3,7 +3,7 @@
<renew> <renew>
<domain:renew <domain:renew
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>create-42.flags</domain:name> <domain:name>%DOMAIN%</domain:name>
<domain:curExpDate>2000-04-03</domain:curExpDate> <domain:curExpDate>2000-04-03</domain:curExpDate>
<domain:period unit="y">1</domain:period> <domain:period unit="y">1</domain:period>
</domain:renew> </domain:renew>

View file

@ -3,7 +3,7 @@
<update> <update>
<domain:update <domain:update
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.flags</domain:name> <domain:name>%DOMAIN%</domain:name>
<domain:chg/> <domain:chg/>
</domain:update> </domain:update>
</update> </update>
@ -11,6 +11,10 @@
<rgp:update xmlns:rgp="urn:ietf:params:xml:ns:rgp-1.0"> <rgp:update xmlns:rgp="urn:ietf:params:xml:ns:rgp-1.0">
<rgp:restore op="request"/> <rgp:restore op="request"/>
</rgp:update> </rgp:update>
<fee:update xmlns:fee="urn:ietf:params:xml:ns:fee-0.6">
<fee:currency>USD</fee:currency>
<fee:fee>%FEE%</fee:fee>
</fee:update>
</extension> </extension>
<clTRID>ABC-12345</clTRID> <clTRID>ABC-12345</clTRID>
</command> </command>