Add extra logic for all relevant flows

This CL enhances various domain flows (check, create, delete, renew, restore, transfer, update) so that they invoke the appropriate methods on the object implementing the TLD's RegistryExtraFlowLogic (if any). TldSpecificLogicProxy is also updated to invoke RegistryExtraFlowLogic proxy (if any) to fetch the appropriate price. The tests use a made-up extra flow logic object which can be attached to a test TLD to make sure that the proper routines are being invoked.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132486734
This commit is contained in:
mountford 2016-09-07 15:23:50 -07:00 committed by Ben McIlwain
parent a6db24c8bb
commit 95cc7ab3d8
46 changed files with 1173 additions and 394 deletions

View file

@ -14,13 +14,24 @@
package google.registry.model.domain;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.base.Ascii;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import google.registry.flows.EppException;
import google.registry.flows.EppException.UnimplementedExtensionException;
import google.registry.flows.domain.RegistryExtraFlowLogic;
import google.registry.model.domain.fee.BaseFee;
import google.registry.model.domain.fee.BaseFee.FeeType;
import google.registry.model.domain.fee.Credit;
import google.registry.model.domain.fee.Fee;
import google.registry.model.domain.flags.FlagsCreateCommandExtension;
import google.registry.model.domain.flags.FlagsTransferCommandExtension;
import google.registry.model.domain.flags.FlagsUpdateCommandExtension;
import google.registry.model.eppinput.EppInput;
import java.math.BigDecimal;
import java.util.List;
import org.joda.time.DateTime;
@ -29,6 +40,8 @@ import org.joda.time.DateTime;
*/
public class TestExtraLogicManager implements RegistryExtraFlowLogic {
private String messageToThrow = null;
@Override
public List<String> getExtensionFlags(
DomainResource domainResource, String clientIdentifier, DateTime asOfDate) {
@ -41,23 +54,166 @@ public class TestExtraLogicManager implements RegistryExtraFlowLogic {
return components.subList(1, components.size());
}
BaseFee domainNameToFeeOrCredit(String domainName) {
// The second-level domain should be of the form "description-price", where description is the
// description string of the fee or credit, and price is the price (credit if negative, fee
// otherwise). To make sure this is a valid domain name, don't use any spaces, and limit prices
// to integers. Don't use a two-character description for credits, since it is illegal to have
// both the third and fourth characters of a domain name label be hyphens.
List<String> components =
Splitter.on('-').limit(2).splitToList(
Iterables.getFirst(Splitter.on('.').split(domainName), ""));
checkArgument(components.size() == 2, "Domain name must be of the form description-price.tld");
int price = Integer.parseInt(components.get(1));
if (price < 0) {
return Credit.create(
new BigDecimal(price), FeeType.valueOf(Ascii.toUpperCase(components.get(0))));
} else {
return Fee.create(
new BigDecimal(price), FeeType.valueOf(Ascii.toUpperCase(components.get(0))));
}
}
/** Computes the expected create cost, for use in fee challenges and the like. */
@Override
public BaseFee getCreateFeeOrCredit(
String domainName,
String clientIdentifier,
DateTime asOfDate,
int years,
EppInput eppInput) throws EppException {
return domainNameToFeeOrCredit(domainName);
}
/**
* Performs additional tasks required for a create command. Any changes should not be persisted to
* Datastore until commitAdditionalLogicChanges is called.
*/
@Override
public void performAdditionalDomainCreateLogic(
DomainResource domain,
String clientIdentifier,
DateTime asOfDate,
int years,
EppInput eppInput) throws EppException {
FlagsCreateCommandExtension flags =
eppInput.getSingleExtension(FlagsCreateCommandExtension.class);
if (flags == null) {
return;
}
messageToThrow = Joiner.on(',').join(flags.getFlags());
}
/**
* Performs additional tasks required for a delete command. Any changes should not be persisted to
* Datastore until commitAdditionalLogicChanges is called.
*/
@Override
public void performAdditionalDomainDeleteLogic(
DomainResource domainResource,
String clientIdentifier,
DateTime asOfDate,
EppInput eppInput) throws EppException {
messageToThrow = "deleted";
}
/** Computes the expected renewal cost, for use in fee challenges and the like. */
@Override
public BaseFee getRenewFeeOrCredit(
DomainResource domain,
String clientIdentifier,
DateTime asOfDate,
int years,
EppInput eppInput) throws EppException {
return domainNameToFeeOrCredit(domain.getFullyQualifiedDomainName());
}
/**
* Performs additional tasks required for a renew command. Any changes should not be persisted
* to Datastore until commitAdditionalLogicChanges is called.
*/
@Override
public void performAdditionalDomainRenewLogic(
DomainResource domainResource,
String clientIdentifier,
DateTime asOfDate,
int years,
EppInput eppInput) throws EppException {
messageToThrow = "renewed";
}
/**
* Performs additional tasks required for a restore command. Any changes should not be persisted
* to Datastore until commitAdditionalLogicChanges is called.
*/
@Override
public void performAdditionalDomainRestoreLogic(
DomainResource domainResource,
String clientIdentifier,
DateTime asOfDate,
EppInput eppInput) throws EppException {
messageToThrow = "restored";
}
/**
* Performs additional tasks required for a transfer command. Any changes should not be persisted
* to Datastore until commitAdditionalLogicChanges is called.
*/
@Override
public void performAdditionalDomainTransferLogic(
DomainResource domainResource,
String clientIdentifier,
DateTime asOfDate,
int years,
EppInput eppInput) throws EppException {
FlagsTransferCommandExtension flags =
eppInput.getSingleExtension(FlagsTransferCommandExtension.class);
if (flags == null) {
return;
}
messageToThrow =
"add:"
+ Joiner.on(',').join(flags.getAddFlags().getFlags())
+ ";remove:"
+ Joiner.on(',').join(flags.getRemoveFlags().getFlags());
}
/** Computes the expected update cost, for use in fee challenges and the like. */
@Override
public BaseFee getUpdateFeeOrCredit(
DomainResource domain,
String clientIdentifier,
DateTime asOfDate,
EppInput eppInput) throws EppException {
return domainNameToFeeOrCredit(domain.getFullyQualifiedDomainName());
}
/**
* Performs additional tasks required for an update command. Any changes should not be persisted
* to Datastore until commitAdditionalLogicChanges is called.
*/
@Override
public void performAdditionalDomainUpdateLogic(
DomainResource domainResource,
String clientIdentifier,
DateTime asOfDate,
EppInput eppInput) throws EppException {
FlagsUpdateCommandExtension updateFlags =
FlagsUpdateCommandExtension flags =
eppInput.getSingleExtension(FlagsUpdateCommandExtension.class);
if (updateFlags == null) {
if (flags == null) {
return;
}
// Throw this exception as a signal to the test that we got this far.
throw new UnimplementedExtensionException();
messageToThrow =
"add:"
+ Joiner.on(',').join(flags.getAddFlags().getFlags())
+ ";remove:"
+ Joiner.on(',').join(flags.getRemoveFlags().getFlags());
}
@Override
public void commitAdditionalDomainUpdates() {
return;
public void commitAdditionalLogicChanges() {
checkNotNull(messageToThrow);
// Throw a specific exception as a signal to the test code that we made it through to here.
throw new IllegalArgumentException(messageToThrow);
}
}