Migrate getCreatePrice() call to DomainPricingLogic

Swap all calls to TldSpecificLogicProxy.getCreatePrice() to the counterpart in
DomainPricingLogic. Also makes necessary changes for testing to work, including
fake implementations of DomainPricingCustomLogic and
DomainCreateLofwCustomLogic.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=140754334
This commit is contained in:
jianglai 2016-12-01 11:20:23 -08:00 committed by Ben McIlwain
parent f8b4c9eddb
commit 79a72387ee
15 changed files with 379 additions and 44 deletions

View file

@ -15,6 +15,7 @@
package google.registry.flows.custom; package google.registry.flows.custom;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
import google.registry.flows.EppException; import google.registry.flows.EppException;
import google.registry.flows.SessionMetadata; import google.registry.flows.SessionMetadata;
@ -22,6 +23,8 @@ import google.registry.flows.domain.DomainCreateFlow;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.model.domain.DomainResource; import google.registry.model.domain.DomainResource;
import google.registry.model.eppinput.EppInput; import google.registry.model.eppinput.EppInput;
import google.registry.model.eppoutput.EppResponse.ResponseData;
import google.registry.model.eppoutput.EppResponse.ResponseExtension;
import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry;
/** /**
@ -60,6 +63,21 @@ public class DomainCreateFlowCustomLogic extends BaseFlowCustomLogic {
return parameters.entityChanges(); return parameters.entityChanges();
} }
/**
* A hook that runs before the response is returned.
*
* <p>This takes the {@link ResponseData} and {@link ResponseExtension}s as input and returns
* them, potentially with modifications.
*/
@SuppressWarnings("unused")
public BeforeResponseReturnData beforeResponse(BeforeResponseParameters parameters)
throws EppException {
return BeforeResponseReturnData.newBuilder()
.setResData(parameters.resData())
.setResponseExtensions(parameters.responseExtensions())
.build();
}
/** A class to encapsulate parameters for a call to {@link #afterValidation}. */ /** A class to encapsulate parameters for a call to {@link #afterValidation}. */
@AutoValue @AutoValue
public abstract static class AfterValidationParameters extends ImmutableObject { public abstract static class AfterValidationParameters extends ImmutableObject {
@ -143,4 +161,56 @@ public class DomainCreateFlowCustomLogic extends BaseFlowCustomLogic {
public abstract BeforeSaveParameters build(); public abstract BeforeSaveParameters build();
} }
} }
/** A class to encapsulate parameters for a call to {@link #beforeResponse}. */
@AutoValue
public abstract static class BeforeResponseParameters extends ImmutableObject {
public abstract ResponseData resData();
public abstract ImmutableList<? extends ResponseExtension> responseExtensions();
public static BeforeResponseParameters.Builder newBuilder() {
return new AutoValue_DomainCreateFlowCustomLogic_BeforeResponseParameters.Builder();
}
/** Builder for {@link DomainCreateFlowCustomLogic.BeforeResponseParameters}. */
@AutoValue.Builder
public abstract static class Builder {
public abstract BeforeResponseParameters.Builder setResData(ResponseData resData);
public abstract BeforeResponseParameters.Builder setResponseExtensions(
ImmutableList<? extends ResponseExtension> responseExtensions);
public abstract BeforeResponseParameters build();
}
}
/**
* A class to encapsulate parameters for the return values from a call to {@link #beforeResponse}.
*/
@AutoValue
public abstract static class BeforeResponseReturnData extends ImmutableObject {
public abstract ResponseData resData();
public abstract ImmutableList<? extends ResponseExtension> responseExtensions();
public static BeforeResponseReturnData.Builder newBuilder() {
return new AutoValue_DomainCreateFlowCustomLogic_BeforeResponseReturnData.Builder();
}
/** Builder for {@link DomainCreateFlowCustomLogic.BeforeResponseReturnData}. */
@AutoValue.Builder
public abstract static class Builder {
public abstract BeforeResponseReturnData.Builder setResData(ResponseData resData);
public abstract BeforeResponseReturnData.Builder setResponseExtensions(
ImmutableList<? extends ResponseExtension> responseExtensions);
public abstract BeforeResponseReturnData build();
}
}
} }

View file

@ -52,7 +52,7 @@ import google.registry.flows.FlowModule.ClientId;
import google.registry.flows.FlowModule.Superuser; import google.registry.flows.FlowModule.Superuser;
import google.registry.flows.FlowModule.TargetId; import google.registry.flows.FlowModule.TargetId;
import google.registry.flows.TransactionalFlow; import google.registry.flows.TransactionalFlow;
import google.registry.flows.domain.TldSpecificLogicProxy.EppCommandOperations; import google.registry.flows.domain.DomainPricingLogic.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.Flag; import google.registry.model.billing.BillingEvent.Flag;
@ -113,6 +113,7 @@ public class DomainAllocateFlow implements TransactionalFlow {
@Inject HistoryEntry.Builder historyBuilder; @Inject HistoryEntry.Builder historyBuilder;
@Inject EppInput eppInput; @Inject EppInput eppInput;
@Inject EppResponse.Builder responseBuilder; @Inject EppResponse.Builder responseBuilder;
@Inject DomainPricingLogic pricingLogic;
@Inject DomainAllocateFlow() {} @Inject DomainAllocateFlow() {}
@Override @Override
@ -389,8 +390,8 @@ public class DomainAllocateFlow implements TransactionalFlow {
private ImmutableList<FeeTransformResponseExtension> createResponseExtensions( private ImmutableList<FeeTransformResponseExtension> createResponseExtensions(
DateTime now, Registry registry, int years) throws EppException { DateTime now, Registry registry, int years) throws EppException {
EppCommandOperations commandOperations = TldSpecificLogicProxy.getCreatePrice( EppCommandOperations commandOperations =
registry, targetId, clientId, now, years, eppInput); pricingLogic.getCreatePrice(registry, targetId, now, years);
FeeCreateCommandExtension feeCreate = FeeCreateCommandExtension feeCreate =
eppInput.getSingleExtension(FeeCreateCommandExtension.class); eppInput.getSingleExtension(FeeCreateCommandExtension.class);
return (feeCreate == null) return (feeCreate == null)

View file

@ -64,7 +64,7 @@ import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.After
import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.BeforeResponseParameters; import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.BeforeResponseParameters;
import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.BeforeResponseReturnData; import google.registry.flows.custom.DomainApplicationCreateFlowCustomLogic.BeforeResponseReturnData;
import google.registry.flows.custom.EntityChanges; import google.registry.flows.custom.EntityChanges;
import google.registry.flows.domain.TldSpecificLogicProxy.EppCommandOperations; import google.registry.flows.domain.DomainPricingLogic.EppCommandOperations;
import google.registry.model.ImmutableObject; import google.registry.model.ImmutableObject;
import google.registry.model.domain.DomainApplication; import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.DomainCommand.Create; import google.registry.model.domain.DomainCommand.Create;
@ -174,6 +174,7 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
@Inject Trid trid; @Inject Trid trid;
@Inject EppResponse.Builder responseBuilder; @Inject EppResponse.Builder responseBuilder;
@Inject DomainApplicationCreateFlowCustomLogic customLogic; @Inject DomainApplicationCreateFlowCustomLogic customLogic;
@Inject DomainPricingLogic pricingLogic;
@Inject DomainApplicationCreateFlow() {} @Inject DomainApplicationCreateFlow() {}
@Override @Override
@ -200,8 +201,8 @@ public final class DomainApplicationCreateFlow implements TransactionalFlow {
String tld = domainName.parent().toString(); String tld = domainName.parent().toString();
checkAllowedAccessToTld(clientId, tld); checkAllowedAccessToTld(clientId, tld);
Registry registry = Registry.get(tld); Registry registry = Registry.get(tld);
EppCommandOperations commandOperations = TldSpecificLogicProxy.getCreatePrice( EppCommandOperations commandOperations =
registry, targetId, clientId, now, command.getPeriod().getValue(), eppInput); pricingLogic.getCreatePrice(registry, targetId, now, command.getPeriod().getValue());
// Superusers can create reserved domains, force creations on domains that require a claims // Superusers can create reserved domains, force creations on domains that require a claims
// notice without specifying a claims key, and override blocks on registering premium domains. // notice without specifying a claims key, and override blocks on registering premium domains.
verifyUnitIsYears(command.getPeriod()); verifyUnitIsYears(command.getPeriod());

View file

@ -110,6 +110,7 @@ public final class DomainCheckFlow implements Flow {
@Inject Clock clock; @Inject Clock clock;
@Inject EppResponse.Builder responseBuilder; @Inject EppResponse.Builder responseBuilder;
@Inject DomainCheckFlowCustomLogic customLogic; @Inject DomainCheckFlowCustomLogic customLogic;
@Inject DomainPricingLogic pricingLogic;
@Inject DomainCheckFlow() {} @Inject DomainCheckFlow() {}
@Override @Override
@ -208,7 +209,8 @@ public final class DomainCheckFlow implements Flow {
clientId, clientId,
feeCheck.getCurrency(), feeCheck.getCurrency(),
now, now,
eppInput); eppInput,
pricingLogic);
responseItems.add(builder.setDomainNameIfSupported(domainName).build()); responseItems.add(builder.setDomainNameIfSupported(domainName).build());
} }
} }

View file

@ -43,7 +43,6 @@ import static google.registry.model.registry.label.ReservedList.matchesAnchorTen
import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static google.registry.util.DateTimeUtils.leapSafeAddYears; import static google.registry.util.DateTimeUtils.leapSafeAddYears;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@ -59,8 +58,10 @@ import google.registry.flows.FlowModule.Superuser;
import google.registry.flows.FlowModule.TargetId; import google.registry.flows.FlowModule.TargetId;
import google.registry.flows.TransactionalFlow; import google.registry.flows.TransactionalFlow;
import google.registry.flows.custom.DomainCreateFlowCustomLogic; import google.registry.flows.custom.DomainCreateFlowCustomLogic;
import google.registry.flows.custom.DomainCreateFlowCustomLogic.BeforeResponseParameters;
import google.registry.flows.custom.DomainCreateFlowCustomLogic.BeforeResponseReturnData;
import google.registry.flows.custom.EntityChanges; import google.registry.flows.custom.EntityChanges;
import google.registry.flows.domain.TldSpecificLogicProxy.EppCommandOperations; import google.registry.flows.domain.DomainPricingLogic.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.Flag; import google.registry.model.billing.BillingEvent.Flag;
@ -166,6 +167,7 @@ public class DomainCreateFlow implements TransactionalFlow {
@Inject HistoryEntry.Builder historyBuilder; @Inject HistoryEntry.Builder historyBuilder;
@Inject EppResponse.Builder responseBuilder; @Inject EppResponse.Builder responseBuilder;
@Inject DomainCreateFlowCustomLogic customLogic; @Inject DomainCreateFlowCustomLogic customLogic;
@Inject DomainPricingLogic pricingLogic;
@Inject DomainCreateFlow() {} @Inject DomainCreateFlow() {}
@Override @Override
@ -211,8 +213,8 @@ public class DomainCreateFlow implements TransactionalFlow {
FeeCreateCommandExtension feeCreate = FeeCreateCommandExtension feeCreate =
eppInput.getSingleExtension(FeeCreateCommandExtension.class); eppInput.getSingleExtension(FeeCreateCommandExtension.class);
EppCommandOperations commandOperations = TldSpecificLogicProxy.getCreatePrice( EppCommandOperations commandOperations =
registry, targetId, clientId, now, years, eppInput); pricingLogic.getCreatePrice(registry, targetId, now, years);
validateFeeChallenge( validateFeeChallenge(
targetId, registry.getTldStr(), now, feeCreate, commandOperations.getTotalCost()); targetId, registry.getTldStr(), now, feeCreate, commandOperations.getTotalCost());
// Superusers can create reserved domains, force creations on domains that require a claims // Superusers can create reserved domains, force creations on domains that require a claims
@ -293,18 +295,6 @@ public class DomainCreateFlow implements TransactionalFlow {
} }
enqueueTasks(hasSignedMarks, hasClaimsNotice, newDomain); enqueueTasks(hasSignedMarks, hasClaimsNotice, newDomain);
// TODO: Remove this section and only use the customLogic.
Optional<RegistryExtraFlowLogic> extraFlowLogic =
RegistryExtraFlowLogicProxy.newInstanceForTld(registry.getTldStr());
if (extraFlowLogic.isPresent()) {
extraFlowLogic.get().performAdditionalDomainCreateLogic(
newDomain,
clientId,
years,
eppInput,
historyEntry);
}
EntityChanges entityChanges = EntityChanges entityChanges =
customLogic.beforeSave( customLogic.beforeSave(
DomainCreateFlowCustomLogic.BeforeSaveParameters.newBuilder() DomainCreateFlowCustomLogic.BeforeSaveParameters.newBuilder()
@ -316,9 +306,15 @@ public class DomainCreateFlow implements TransactionalFlow {
.build()); .build());
persistEntityChanges(entityChanges); persistEntityChanges(entityChanges);
return responseBuilder BeforeResponseReturnData responseData =
customLogic.beforeResponse(
BeforeResponseParameters.newBuilder()
.setResData(DomainCreateData.create(targetId, now, registrationExpirationTime)) .setResData(DomainCreateData.create(targetId, now, registrationExpirationTime))
.setExtensions(createResponseExtensions(feeCreate, commandOperations)) .setResponseExtensions(createResponseExtensions(feeCreate, commandOperations))
.build());
return responseBuilder
.setResData(responseData.resData())
.setExtensions(responseData.responseExtensions())
.build(); .build();
} }

View file

@ -56,7 +56,7 @@ import google.registry.flows.EppException.ParameterValueSyntaxErrorException;
import google.registry.flows.EppException.RequiredParameterMissingException; import google.registry.flows.EppException.RequiredParameterMissingException;
import google.registry.flows.EppException.StatusProhibitsOperationException; import google.registry.flows.EppException.StatusProhibitsOperationException;
import google.registry.flows.EppException.UnimplementedOptionException; import google.registry.flows.EppException.UnimplementedOptionException;
import google.registry.flows.domain.TldSpecificLogicProxy.EppCommandOperations; import google.registry.flows.domain.DomainPricingLogic.EppCommandOperations;
import google.registry.flows.exceptions.ResourceAlreadyExistsException; import google.registry.flows.exceptions.ResourceAlreadyExistsException;
import google.registry.flows.exceptions.ResourceHasClientUpdateProhibitedException; import google.registry.flows.exceptions.ResourceHasClientUpdateProhibitedException;
import google.registry.model.EppResource; import google.registry.model.EppResource;
@ -589,7 +589,9 @@ public class DomainFlowUtils {
String clientId, String clientId,
@Nullable CurrencyUnit topLevelCurrency, @Nullable CurrencyUnit topLevelCurrency,
DateTime currentDate, DateTime currentDate,
EppInput eppInput) throws EppException { EppInput eppInput,
DomainPricingLogic pricingLogic)
throws EppException {
DateTime now = currentDate; DateTime now = currentDate;
// Use the custom effective date specified in the fee check request, if there is one. // Use the custom effective date specified in the fee check request, if there is one.
if (feeRequest.getEffectiveDate().isPresent()) { if (feeRequest.getEffectiveDate().isPresent()) {
@ -626,8 +628,7 @@ public class DomainFlowUtils {
builder.setReasonIfSupported("reserved"); builder.setReasonIfSupported("reserved");
} else { } else {
builder.setAvailIfSupported(true); builder.setAvailIfSupported(true);
fees = TldSpecificLogicProxy.getCreatePrice( fees = pricingLogic.getCreatePrice(registry, domainNameString, now, years).getFees();
registry, domainNameString, clientId, now, years, eppInput).getFees();
} }
break; break;
case RENEW: case RENEW:

View file

@ -77,6 +77,7 @@ public final class DomainInfoFlow implements Flow {
@Inject Clock clock; @Inject Clock clock;
@Inject EppResponse.Builder responseBuilder; @Inject EppResponse.Builder responseBuilder;
@Inject DomainInfoFlowCustomLogic customLogic; @Inject DomainInfoFlowCustomLogic customLogic;
@Inject DomainPricingLogic pricingLogic;
@Inject @Inject
DomainInfoFlow() {} DomainInfoFlow() {}
@ -145,7 +146,14 @@ public final class DomainInfoFlow implements Flow {
if (feeInfo != null) { // Fee check was requested. if (feeInfo != null) { // Fee check was requested.
FeeInfoResponseExtensionV06.Builder builder = new FeeInfoResponseExtensionV06.Builder(); FeeInfoResponseExtensionV06.Builder builder = new FeeInfoResponseExtensionV06.Builder();
handleFeeRequest( handleFeeRequest(
feeInfo, builder, InternetDomainName.from(targetId), clientId, null, now, eppInput); feeInfo,
builder,
InternetDomainName.from(targetId),
clientId,
null,
now,
eppInput,
pricingLogic);
extensions.add(builder.build()); extensions.add(builder.build());
} }
// If the TLD uses the flags extension, add it to the info response. // If the TLD uses the flags extension, add it to the info response.

View file

@ -63,6 +63,18 @@ public abstract class CreateData implements ResponseData {
instance.expirationDate = expirationDate; instance.expirationDate = expirationDate;
return instance; return instance;
} }
public String name() {
return name;
}
public DateTime creationDate() {
return creationDate;
}
public DateTime expirationDate() {
return expirationDate;
}
} }
/** An acknowledgment message indicating that a host was created. */ /** An acknowledgment message indicating that a host was created. */

View file

@ -23,7 +23,8 @@ import dagger.Provides;
import dagger.Subcomponent; import dagger.Subcomponent;
import google.registry.config.ConfigModule; import google.registry.config.ConfigModule;
import google.registry.dns.DnsQueue; import google.registry.dns.DnsQueue;
import google.registry.flows.custom.CustomLogicFactoryModule; import google.registry.flows.custom.CustomLogicFactory;
import google.registry.flows.custom.TestCustomLogicFactory;
import google.registry.monitoring.whitebox.BigQueryMetricsEnqueuer; import google.registry.monitoring.whitebox.BigQueryMetricsEnqueuer;
import google.registry.monitoring.whitebox.EppMetric; import google.registry.monitoring.whitebox.EppMetric;
import google.registry.request.RequestScope; import google.registry.request.RequestScope;
@ -38,7 +39,6 @@ import javax.inject.Singleton;
@Component( @Component(
modules = { modules = {
ConfigModule.class, ConfigModule.class,
CustomLogicFactoryModule.class,
EppTestComponent.FakesAndMocksModule.class EppTestComponent.FakesAndMocksModule.class
}) })
interface EppTestComponent { interface EppTestComponent {
@ -94,6 +94,11 @@ interface EppTestComponent {
BigQueryMetricsEnqueuer provideBigQueryMetricsEnqueuer() { BigQueryMetricsEnqueuer provideBigQueryMetricsEnqueuer() {
return metricsEnqueuer; return metricsEnqueuer;
} }
@Provides
CustomLogicFactory provideCustomLogicFactory() {
return new TestCustomLogicFactory();
}
} }
/** Subcomponent for request scoped injections. */ /** Subcomponent for request scoped injections. */

View file

@ -0,0 +1,40 @@
// Copyright 2016 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.flows.custom;
import google.registry.flows.SessionMetadata;
import google.registry.model.eppinput.EppInput;
/** A custom logic factory for testing. */
public class TestCustomLogicFactory extends CustomLogicFactory {
@Override
public DomainPricingCustomLogic forDomainPricing(
EppInput eppInput, SessionMetadata sessionMetadata) {
return new TestDomainPricingCustomLogic(eppInput, sessionMetadata);
}
@Override
public DomainCreateFlowCustomLogic forDomainCreateFlow(
EppInput eppInput, SessionMetadata sessionMetadata) {
return new TestDomainCreateFlowCustomLogic(eppInput, sessionMetadata);
}
@Override
public DomainApplicationCreateFlowCustomLogic forDomainApplicationCreateFlow(
EppInput eppInput, SessionMetadata sessionMetadata) {
return new TestDomainApplicationCreateFlowCustomLogic(eppInput, sessionMetadata);
}
}

View file

@ -0,0 +1,63 @@
// Copyright 2016 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.flows.custom;
import com.google.common.base.Joiner;
import com.google.common.net.InternetDomainName;
import google.registry.flows.SessionMetadata;
import google.registry.flows.domain.DomainApplicationCreateFlow;
import google.registry.model.domain.flags.FlagsCreateCommandExtension;
import google.registry.model.eppinput.EppInput;
import google.registry.model.eppoutput.CreateData.DomainCreateData;
/** A class to customize {@link DomainApplicationCreateFlow} for testing. */
public class TestDomainApplicationCreateFlowCustomLogic
extends DomainApplicationCreateFlowCustomLogic {
protected TestDomainApplicationCreateFlowCustomLogic(
EppInput eppInput, SessionMetadata sessionMetadata) {
super(eppInput, sessionMetadata);
}
private String getTld() {
return InternetDomainName.from(getEppInput().getTargetIds().get(0)).parent().toString();
}
@Override
public BeforeResponseReturnData beforeResponse(BeforeResponseParameters parameters) {
if (getTld().equals("flags")) {
String flagsPrefix =
Joiner.on('-')
.join(getEppInput().getSingleExtension(FlagsCreateCommandExtension.class).getFlags());
DomainCreateData resData = (DomainCreateData) parameters.resData();
resData =
DomainCreateData.create(
Joiner.on('-').join(flagsPrefix, resData.name()),
resData.creationDate(),
resData.expirationDate());
return BeforeResponseReturnData.newBuilder()
.setResData(resData)
.setResponseExtensions(parameters.responseExtensions())
.build();
} else {
return BeforeResponseReturnData.newBuilder()
.setResData(parameters.resData())
.setResponseExtensions(parameters.responseExtensions())
.build();
}
}
}

View file

@ -0,0 +1,61 @@
// Copyright 2016 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.flows.custom;
import com.google.common.base.Joiner;
import com.google.common.net.InternetDomainName;
import google.registry.flows.SessionMetadata;
import google.registry.flows.domain.DomainCreateFlow;
import google.registry.model.domain.flags.FlagsCreateCommandExtension;
import google.registry.model.eppinput.EppInput;
import google.registry.model.eppoutput.CreateData.DomainCreateData;
/** A class to customize {@link DomainCreateFlow} for testing. */
public class TestDomainCreateFlowCustomLogic extends DomainCreateFlowCustomLogic {
protected TestDomainCreateFlowCustomLogic(EppInput eppInput, SessionMetadata sessionMetadata) {
super(eppInput, sessionMetadata);
}
private String getTld() {
return InternetDomainName.from(getEppInput().getTargetIds().get(0)).parent().toString();
}
@Override
public BeforeResponseReturnData beforeResponse(BeforeResponseParameters parameters) {
if (getTld().equals("flags")) {
String flagsPrefix =
Joiner.on('-')
.join(getEppInput().getSingleExtension(FlagsCreateCommandExtension.class).getFlags());
DomainCreateData resData = (DomainCreateData) parameters.resData();
resData =
DomainCreateData.create(
Joiner.on('-').join(flagsPrefix, resData.name()),
resData.creationDate(),
resData.expirationDate());
return BeforeResponseReturnData.newBuilder()
.setResData(resData)
.setResponseExtensions(parameters.responseExtensions())
.build();
} else {
return BeforeResponseReturnData.newBuilder()
.setResData(parameters.resData())
.setResponseExtensions(parameters.responseExtensions())
.build();
}
}
}

View file

@ -0,0 +1,73 @@
// Copyright 2016 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.flows.custom;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.Ascii;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.net.InternetDomainName;
import google.registry.flows.EppException;
import google.registry.flows.SessionMetadata;
import google.registry.flows.domain.DomainPricingLogic;
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.eppinput.EppInput;
import java.math.BigDecimal;
import java.util.List;
/** A class to customize {@link DomainPricingLogic} for testing. */
public class TestDomainPricingCustomLogic extends DomainPricingCustomLogic {
protected TestDomainPricingCustomLogic(EppInput eppInput, SessionMetadata sessionMetadata) {
super(eppInput, sessionMetadata);
}
private static BaseFee domainNameToFeeOrCredit(InternetDomainName 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.toString()), ""));
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))));
}
}
/** A hook that customizes create price. */
@Override
public BaseFee customizeCreatePrice(CreatePriceParameters createPriceParameters)
throws EppException {
InternetDomainName domainName = createPriceParameters.domainName();
if (domainName.parent().toString().equals("flags")) {
return domainNameToFeeOrCredit(domainName);
} else {
return createPriceParameters.createFee();
}
}
}

View file

@ -105,13 +105,13 @@ import google.registry.flows.exceptions.ResourceAlreadyExistsException;
import google.registry.model.domain.DomainApplication; import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.GracePeriod; import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.LrpTokenEntity; import google.registry.model.domain.LrpTokenEntity;
import google.registry.model.domain.TestExtraLogicManager;
import google.registry.model.domain.TestExtraLogicManager.TestExtraLogicManagerSuccessException;
import google.registry.model.domain.launch.ApplicationStatus; import google.registry.model.domain.launch.ApplicationStatus;
import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.launch.LaunchPhase; import google.registry.model.domain.launch.LaunchPhase;
import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppoutput.CreateData.DomainCreateData;
import google.registry.model.eppoutput.EppOutput;
import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState; import google.registry.model.registry.Registry.TldState;
@ -158,7 +158,6 @@ public class DomainApplicationCreateFlowTest
createTld("tld", TldState.SUNRISE); createTld("tld", TldState.SUNRISE);
persistResource(Registry.get("tld").asBuilder().setReservedLists(createReservedList()).build()); persistResource(Registry.get("tld").asBuilder().setReservedLists(createReservedList()).build());
createTld("flags", TldState.LANDRUSH); createTld("flags", TldState.LANDRUSH);
RegistryExtraFlowLogicProxy.setOverride("flags", TestExtraLogicManager.class);
persistResource( persistResource(
Registry.get("flags").asBuilder().setReservedLists(createReservedList()).build()); Registry.get("flags").asBuilder().setReservedLists(createReservedList()).build());
inject.setStaticField(TmchCertificateAuthority.class, "clock", clock); inject.setStaticField(TmchCertificateAuthority.class, "clock", clock);
@ -1705,7 +1704,9 @@ public class DomainApplicationCreateFlowTest
public void testSuccess_flags() throws Exception { public void testSuccess_flags() throws Exception {
persistContactsAndHosts(); persistContactsAndHosts();
setEppInput("domain_create_landrush_flags.xml", ImmutableMap.of("FEE", "42")); setEppInput("domain_create_landrush_flags.xml", ImmutableMap.of("FEE", "42"));
thrown.expect(TestExtraLogicManagerSuccessException.class, "flag1,flag2"); EppOutput eppOutput = runFlow();
runFlow(); String domainNameWithFlagsPrefix =
((DomainCreateData) eppOutput.getResponse().getResponseData().get(0)).name();
assertThat(domainNameWithFlagsPrefix).isEqualTo("flag1-flag2-create-42.flags");
} }
} }

View file

@ -109,13 +109,13 @@ import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainResource; import google.registry.model.domain.DomainResource;
import google.registry.model.domain.GracePeriod; import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.LrpTokenEntity; import google.registry.model.domain.LrpTokenEntity;
import google.registry.model.domain.TestExtraLogicManager;
import google.registry.model.domain.TestExtraLogicManager.TestExtraLogicManagerSuccessException;
import google.registry.model.domain.launch.ApplicationStatus; import google.registry.model.domain.launch.ApplicationStatus;
import google.registry.model.domain.launch.LaunchNotice; import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import google.registry.model.eppoutput.CreateData.DomainCreateData;
import google.registry.model.eppoutput.EppOutput;
import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState; import google.registry.model.registry.Registry.TldState;
@ -151,7 +151,6 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
"anchor,RESERVED_FOR_ANCHOR_TENANT,2fooBAR")) "anchor,RESERVED_FOR_ANCHOR_TENANT,2fooBAR"))
.build()); .build());
persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY)); persistClaimsList(ImmutableMap.of("example-one", CLAIMS_KEY));
RegistryExtraFlowLogicProxy.setOverride("flags", TestExtraLogicManager.class);
} }
/** /**
@ -1710,7 +1709,9 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
public void testSuccess_flags() throws Exception { public void testSuccess_flags() throws Exception {
persistContactsAndHosts(); persistContactsAndHosts();
setEppInput("domain_create_flags.xml", ImmutableMap.of("FEE", "42")); setEppInput("domain_create_flags.xml", ImmutableMap.of("FEE", "42"));
thrown.expect(TestExtraLogicManagerSuccessException.class, "flag1,flag2"); EppOutput eppOutput = runFlow();
runFlow(); String domainNameWithFlagsPrefix =
((DomainCreateData) eppOutput.getResponse().getResponseData().get(0)).name();
assertThat(domainNameWithFlagsPrefix).isEqualTo("flag1-flag2-create-42.flags");
} }
} }