Use TldSpecificLogicProxy to fetch renew price in DomainRenewFlow

The renew flow was still using PricingEngineProxy directly, meaning that it did not pick up on any TLD-specific pricing logic. Fixed this, and added tests to make sure.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=136757922
This commit is contained in:
mountford 2016-10-20 14:10:43 -07:00 committed by Ben McIlwain
parent ae7933da57
commit fd1c68ffb9
4 changed files with 34 additions and 8 deletions

View file

@ -29,7 +29,6 @@ import static google.registry.model.domain.DomainResource.extendRegistrationWith
import static google.registry.model.domain.fee.Fee.FEE_RENEW_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER; import static google.registry.model.domain.fee.Fee.FEE_RENEW_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.leapSafeAddYears; import static google.registry.util.DateTimeUtils.leapSafeAddYears;
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.billing.BillingEvent; import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.OneTime; import google.registry.model.billing.BillingEvent.OneTime;
import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.billing.BillingEvent.Reason;
@ -122,10 +122,12 @@ public final class DomainRenewFlow extends LoggedInFlow implements Transactional
DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now); DomainResource existingDomain = loadAndVerifyExistence(DomainResource.class, targetId, now);
verifyRenewAllowed(authInfo, existingDomain, command); verifyRenewAllowed(authInfo, existingDomain, command);
int years = command.getPeriod().getValue(); int years = command.getPeriod().getValue();
Money renewCost = getDomainRenewCost(targetId, now, years);
FeeTransformCommandExtension feeRenew = FeeTransformCommandExtension feeRenew =
eppInput.getFirstExtensionOfClasses(FEE_RENEW_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER); eppInput.getFirstExtensionOfClasses(FEE_RENEW_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER);
validateFeeChallenge(targetId, existingDomain.getTld(), now, feeRenew, renewCost); EppCommandOperations commandOperations = TldSpecificLogicProxy.getRenewPrice(
Registry.get(existingDomain.getTld()), targetId, clientId, now, years, eppInput);
validateFeeChallenge(
targetId, existingDomain.getTld(), now, feeRenew, commandOperations.getTotalCost());
HistoryEntry historyEntry = historyBuilder HistoryEntry historyEntry = historyBuilder
.setType(HistoryEntry.Type.DOMAIN_RENEW) .setType(HistoryEntry.Type.DOMAIN_RENEW)
.setPeriod(command.getPeriod()) .setPeriod(command.getPeriod())
@ -140,7 +142,7 @@ public final class DomainRenewFlow extends LoggedInFlow implements Transactional
String tld = existingDomain.getTld(); String tld = existingDomain.getTld();
// Bill for this explicit renew itself. // Bill for this explicit renew itself.
BillingEvent.OneTime explicitRenewEvent = BillingEvent.OneTime explicitRenewEvent =
createRenewBillingEvent(tld, renewCost, years, historyEntry); createRenewBillingEvent(tld, commandOperations.getTotalCost(), years, historyEntry);
// Create a new autorenew billing event and poll message starting at the new expiration time. // Create a new autorenew billing event and poll message starting at the new expiration time.
BillingEvent.Recurring newAutorenewEvent = newAutorenewBillingEvent(existingDomain) BillingEvent.Recurring newAutorenewEvent = newAutorenewBillingEvent(existingDomain)
.setEventTime(newExpirationTime) .setEventTime(newExpirationTime)
@ -171,7 +173,7 @@ public final class DomainRenewFlow extends LoggedInFlow implements Transactional
return createOutput( return createOutput(
SUCCESS, SUCCESS,
DomainRenewData.create(targetId, newExpirationTime), DomainRenewData.create(targetId, newExpirationTime),
createResponseExtensions(renewCost, feeRenew)); createResponseExtensions(commandOperations.getTotalCost(), feeRenew));
} }
private void verifyRenewAllowed( private void verifyRenewAllowed(

View file

@ -613,11 +613,20 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
runFlow(); runFlow();
} }
@Test
public void testFailure_flags_feeMismatch() throws Exception {
setEppInput("domain_renew_flags.xml", ImmutableMap.of("FEE", "11"));
persistDomain();
thrown.expect(FeesMismatchException.class);
runFlow();
}
@Test @Test
public void testSuccess_flags() throws Exception { public void testSuccess_flags() throws Exception {
setEppInput("domain_renew_flags.xml"); setEppInput("domain_renew_flags.xml", ImmutableMap.of("FEE", "42"));
persistDomain(); persistDomain();
thrown.expect(TestExtraLogicManagerSuccessException.class, "renewed"); thrown.expect(TestExtraLogicManagerSuccessException.class, "renewed");
runFlow(); runFlow();
} }
} }

View file

@ -3,11 +3,17 @@
<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>example.flags</domain:name> <domain:name>create-42.flags</domain:name>
<domain:curExpDate>2000-04-03</domain:curExpDate> <domain:curExpDate>2000-04-03</domain:curExpDate>
<domain:period unit="y">5</domain:period> <domain:period unit="y">1</domain:period>
</domain:renew> </domain:renew>
</renew> </renew>
<extension>
<fee:renew xmlns:fee="urn:ietf:params:xml:ns:fee-0.6">
<fee:currency>USD</fee:currency>
<fee:fee>%FEE%</fee:fee>
</fee:renew>
</extension>
<clTRID>ABC-12345</clTRID> <clTRID>ABC-12345</clTRID>
</command> </command>
</epp> </epp>

View file

@ -58,6 +58,15 @@ public class TestExtraLogicManager implements RegistryExtraFlowLogic {
} }
} }
/**
* Gets the flags to be used in the EPP flags extension for info commands.
*
* <p>The test extra logic manager uses domain names differently for info commands than for other
* flows. In other flows, the test logic needs returns (via the success exception) the flags found
* in the incoming message. But for info commands, there aren't any incoming flags, only outgoing
* ones. So we need to specify the flags using a dummy domain name; those flags can then be
* inserted into the outgoing info response.
*/
@Override @Override
public Set<String> getExtensionFlags( public Set<String> getExtensionFlags(
DomainResource domainResource, String clientId, DateTime asOfDate) { DomainResource domainResource, String clientId, DateTime asOfDate) {