mirror of
https://github.com/google/nomulus.git
synced 2025-08-06 09:45:19 +02:00
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:
parent
f8b4c9eddb
commit
79a72387ee
15 changed files with 379 additions and 44 deletions
|
@ -23,7 +23,8 @@ import dagger.Provides;
|
|||
import dagger.Subcomponent;
|
||||
import google.registry.config.ConfigModule;
|
||||
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.EppMetric;
|
||||
import google.registry.request.RequestScope;
|
||||
|
@ -38,7 +39,6 @@ import javax.inject.Singleton;
|
|||
@Component(
|
||||
modules = {
|
||||
ConfigModule.class,
|
||||
CustomLogicFactoryModule.class,
|
||||
EppTestComponent.FakesAndMocksModule.class
|
||||
})
|
||||
interface EppTestComponent {
|
||||
|
@ -94,6 +94,11 @@ interface EppTestComponent {
|
|||
BigQueryMetricsEnqueuer provideBigQueryMetricsEnqueuer() {
|
||||
return metricsEnqueuer;
|
||||
}
|
||||
|
||||
@Provides
|
||||
CustomLogicFactory provideCustomLogicFactory() {
|
||||
return new TestCustomLogicFactory();
|
||||
}
|
||||
}
|
||||
|
||||
/** Subcomponent for request scoped injections. */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -105,13 +105,13 @@ import google.registry.flows.exceptions.ResourceAlreadyExistsException;
|
|||
import google.registry.model.domain.DomainApplication;
|
||||
import google.registry.model.domain.GracePeriod;
|
||||
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.LaunchNotice;
|
||||
import google.registry.model.domain.launch.LaunchPhase;
|
||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||
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.registry.Registry;
|
||||
import google.registry.model.registry.Registry.TldState;
|
||||
|
@ -158,7 +158,6 @@ public class DomainApplicationCreateFlowTest
|
|||
createTld("tld", TldState.SUNRISE);
|
||||
persistResource(Registry.get("tld").asBuilder().setReservedLists(createReservedList()).build());
|
||||
createTld("flags", TldState.LANDRUSH);
|
||||
RegistryExtraFlowLogicProxy.setOverride("flags", TestExtraLogicManager.class);
|
||||
persistResource(
|
||||
Registry.get("flags").asBuilder().setReservedLists(createReservedList()).build());
|
||||
inject.setStaticField(TmchCertificateAuthority.class, "clock", clock);
|
||||
|
@ -1705,7 +1704,9 @@ public class DomainApplicationCreateFlowTest
|
|||
public void testSuccess_flags() throws Exception {
|
||||
persistContactsAndHosts();
|
||||
setEppInput("domain_create_landrush_flags.xml", ImmutableMap.of("FEE", "42"));
|
||||
thrown.expect(TestExtraLogicManagerSuccessException.class, "flag1,flag2");
|
||||
runFlow();
|
||||
EppOutput eppOutput = runFlow();
|
||||
String domainNameWithFlagsPrefix =
|
||||
((DomainCreateData) eppOutput.getResponse().getResponseData().get(0)).name();
|
||||
assertThat(domainNameWithFlagsPrefix).isEqualTo("flag1-flag2-create-42.flags");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,13 +109,13 @@ import google.registry.model.billing.BillingEvent.Reason;
|
|||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.domain.GracePeriod;
|
||||
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.LaunchNotice;
|
||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||
import google.registry.model.domain.secdns.DelegationSignerData;
|
||||
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.registry.Registry;
|
||||
import google.registry.model.registry.Registry.TldState;
|
||||
|
@ -151,7 +151,6 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
|||
"anchor,RESERVED_FOR_ANCHOR_TENANT,2fooBAR"))
|
||||
.build());
|
||||
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 {
|
||||
persistContactsAndHosts();
|
||||
setEppInput("domain_create_flags.xml", ImmutableMap.of("FEE", "42"));
|
||||
thrown.expect(TestExtraLogicManagerSuccessException.class, "flag1,flag2");
|
||||
runFlow();
|
||||
EppOutput eppOutput = runFlow();
|
||||
String domainNameWithFlagsPrefix =
|
||||
((DomainCreateData) eppOutput.getResponse().getResponseData().get(0)).name();
|
||||
assertThat(domainNameWithFlagsPrefix).isEqualTo("flag1-flag2-create-42.flags");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue