Refactor Fee class to support EAP fee

Currently EapFee is a separate class that has no inheritance from either
BaseFee and Fee. With this CL its functionality is merged into the Fee class
and the type of the fee can be identified by the FeeType enum in the Fee class.
Future custom fees can follow the same pattern.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=133627570
This commit is contained in:
jianglai 2016-09-19 13:53:38 -07:00 committed by Ben McIlwain
parent 0518f63aad
commit 77571e2063
9 changed files with 121 additions and 131 deletions

View file

@ -171,7 +171,8 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
Money cost = getPricesForDomainName(getUniqueIdFromCommand(), clock.nowUtc()).isPremium()
? Money.of(USD, 200)
: Money.of(USD, 26);
Money eapFee = Registry.get(domainTld).getEapFeeFor(clock.nowUtc()).getCost();
Money eapFee = Money.of(Registry.get(domainTld).getCurrency(),
Registry.get(domainTld).getEapFeeFor(clock.nowUtc()).getCost());
DateTime billingTime = isAnchorTenant
? clock.nowUtc().plus(Registry.get(domainTld).getAnchorTenantAddGracePeriodLength())

View file

@ -24,6 +24,7 @@ import static org.joda.money.CurrencyUnit.USD;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Range;
import com.googlecode.objectify.Key;
import google.registry.flows.ResourceMutateFlow.ResourceToMutateDoesNotExistException;
import google.registry.model.domain.DomainResource;
@ -56,14 +57,11 @@ import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class TldSpecificLogicProxyTest extends ShardableTestCase {
@Rule
public final InjectRule inject = new InjectRule();
@Rule public final InjectRule inject = new InjectRule();
@Rule
public final ExceptionRule thrown = new ExceptionRule();
@Rule public final ExceptionRule thrown = new ExceptionRule();
@Rule
public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
@Rule public final AppEngineRule appEngine = AppEngineRule.builder().withDatastore().build();
final FakeClock clock = new FakeClock(DateTime.parse("2010-01-01T10:00:00Z"));
@ -97,26 +95,36 @@ public class TldSpecificLogicProxyTest extends ShardableTestCase {
assertThat(createPrice.getTotalCost()).isEqualTo(basicCreateCost);
assertThat(createPrice.getFees()).hasSize(1);
}
@Test
public void test_eap() throws Exception {
TldSpecificLogicProxy.EppCommandOperations createPrice =
TldSpecificLogicProxy.getCreatePrice(
Registry.get("eap"), "example.eap", "clientIdentifier", clock.nowUtc(), 1, null);
Range<DateTime> eapValidPeriod =
Range.closedOpen(clock.nowUtc().minusDays(1), clock.nowUtc().plusDays(1));
assertThat(createPrice.getTotalCost()).isEqualTo(basicCreateCost.plus(Money.of(USD, 100)));
assertThat(createPrice.getCurrency()).isEqualTo(USD);
assertThat(createPrice.getFees().get(0))
.isEqualTo(Fee.create(basicCreateCost.getAmount(), FeeType.CREATE));
assertThat(createPrice.getFees().get(1))
.isEqualTo(
Fee.create(Money.of(USD, 100).getAmount(), FeeType.EAP, clock.nowUtc().plusDays(1)));
Fee.create(
new BigDecimal("100.00"),
FeeType.EAP,
eapValidPeriod,
clock.nowUtc().plusDays(1)));
assertThat(createPrice.getFees())
.containsExactly(
Fee.create(basicCreateCost.getAmount(), FeeType.CREATE),
Fee.create(Money.of(USD, 100).getAmount(), FeeType.EAP, clock.nowUtc().plusDays(1)))
Fee.create(
new BigDecimal("100.00"),
FeeType.EAP,
eapValidPeriod,
clock.nowUtc().plusDays(1)))
.inOrder();
}
@Test
public void test_extraLogic_createPrice() throws Exception {
TldSpecificLogicProxy.EppCommandOperations price =
@ -128,7 +136,7 @@ public class TldSpecificLogicProxyTest extends ShardableTestCase {
assertThat(price.getFees().get(0).getDescription()).isEqualTo("create");
assertThat(price.getCredits()).isEmpty();
}
@Test
public void test_extraLogic_renewPrice() throws Exception {
persistActiveDomain("renew--13.test");
@ -141,34 +149,40 @@ public class TldSpecificLogicProxyTest extends ShardableTestCase {
assertThat(price.getCredits().get(0).getCost()).isEqualTo(new BigDecimal(-13));
assertThat(price.getCredits().get(0).getDescription()).isEqualTo("renew");
}
@Test
public void test_extraLogic_renewPrice_noDomain() throws Exception {
thrown.expect(ResourceToMutateDoesNotExistException.class);
TldSpecificLogicProxy.getRenewPrice(
Registry.get("test"), "renew--13.test", "clientIdentifier", clock.nowUtc(), 1, null);
}
void persistPendingDeleteDomain(String domainName, DateTime now) throws Exception {
DomainResource domain = newDomainResource(domainName);
HistoryEntry historyEntry = persistResource(
new HistoryEntry.Builder()
.setType(HistoryEntry.Type.DOMAIN_DELETE)
.setParent(domain)
.build());
domain = persistResource(domain.asBuilder()
.setRegistrationExpirationTime(now.plusYears(5).plusDays(45))
.setDeletionTime(now.plusDays(35))
.addGracePeriod(GracePeriod.create(
GracePeriodStatus.REDEMPTION, now.plusDays(1), "foo", null))
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.setDeletePollMessage(Key.create(persistResource(
new PollMessage.OneTime.Builder()
.setClientId("TheRegistrar")
.setEventTime(now.plusDays(5))
.setParent(historyEntry)
.build())))
.build());
HistoryEntry historyEntry =
persistResource(
new HistoryEntry.Builder()
.setType(HistoryEntry.Type.DOMAIN_DELETE)
.setParent(domain)
.build());
domain =
persistResource(
domain
.asBuilder()
.setRegistrationExpirationTime(now.plusYears(5).plusDays(45))
.setDeletionTime(now.plusDays(35))
.addGracePeriod(
GracePeriod.create(GracePeriodStatus.REDEMPTION, now.plusDays(1), "foo", null))
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE))
.setDeletePollMessage(
Key.create(
persistResource(
new PollMessage.OneTime.Builder()
.setClientId("TheRegistrar")
.setEventTime(now.plusDays(5))
.setParent(historyEntry)
.build())))
.build());
clock.advanceOneMilli();
}
@ -185,14 +199,14 @@ public class TldSpecificLogicProxyTest extends ShardableTestCase {
assertThat(price.getFees().get(1).getDescription()).isEqualTo("restore");
assertThat(price.getCredits()).isEmpty();
}
@Test
public void test_extraLogic_restorePrice_noDomain() throws Exception {
thrown.expect(ResourceToMutateDoesNotExistException.class);
TldSpecificLogicProxy.getRestorePrice(
Registry.get("test"), "renew-13.test", "clientIdentifier", clock.nowUtc(), null);
}
@Test
public void test_extraLogic_transferPrice() throws Exception {
persistActiveDomain("renew-26.test");
@ -205,7 +219,7 @@ public class TldSpecificLogicProxyTest extends ShardableTestCase {
assertThat(price.getFees().get(0).getDescription()).isEqualTo("renew");
assertThat(price.getCredits()).isEmpty();
}
@Test
public void test_extraLogic_updatePrice() throws Exception {
persistActiveDomain("update-13.test");

View file

@ -38,6 +38,7 @@ import google.registry.model.registry.Registry.TldState;
import google.registry.model.registry.label.PremiumList;
import google.registry.model.registry.label.ReservedList;
import google.registry.testing.ExceptionRule;
import java.math.BigDecimal;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.Before;
@ -414,7 +415,7 @@ public class RegistryTest extends EntityTestCase {
@Test
public void testEapFee_undefined() {
assertThat(Registry.get("tld").getEapFeeFor(clock.nowUtc()).getCost())
.isEqualTo(Money.of(USD, 0));
.isEqualTo(BigDecimal.ZERO.setScale(2));
}
@Test
@ -428,11 +429,12 @@ public class RegistryTest extends EntityTestCase {
a, Money.of(USD, 100),
b, Money.of(USD, 50))).build();
assertThat(registry.getEapFeeFor(clock.nowUtc()).getCost()).isEqualTo(Money.of(USD, 100));
assertThat(registry.getEapFeeFor(clock.nowUtc()).getCost())
.isEqualTo(new BigDecimal("100.00"));
assertThat(registry.getEapFeeFor(clock.nowUtc().minusDays(2)).getCost())
.isEqualTo(Money.of(USD, 0));
.isEqualTo(BigDecimal.ZERO.setScale(2));
assertThat(registry.getEapFeeFor(clock.nowUtc().plusDays(2)).getCost())
.isEqualTo(Money.of(USD, 50));
.isEqualTo(new BigDecimal("50.00"));
}
@Test

View file

@ -32,6 +32,7 @@ import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.math.BigDecimal;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.Before;
@ -103,10 +104,12 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
"xn--q9jyb4c");
Registry registry = Registry.get("xn--q9jyb4c");
assertThat(registry.getEapFeeFor(now.minusHours(1)).getCost()).isEqualTo(Money.zero(USD));
assertThat(registry.getEapFeeFor(now.plusHours(1)).getCost()).isEqualTo(Money.of(USD, 50));
assertThat(registry.getEapFeeFor(now.minusHours(1)).getCost())
.isEqualTo(BigDecimal.ZERO.setScale(2));
assertThat(registry.getEapFeeFor(now.plusHours(1)).getCost())
.isEqualTo(new BigDecimal("50.00"));
assertThat(registry.getEapFeeFor(now.plusDays(1).plusHours(1)).getCost())
.isEqualTo(Money.of(USD, 10));
.isEqualTo(new BigDecimal("10.00"));
}
@Test
@ -155,8 +158,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test
public void testSuccess_createBillingCostFlag() throws Exception {
runCommandForced(
"--create_billing_cost=\"USD 42.42\"", "--roid_suffix=Q9JYB4C", "xn--q9jyb4c");
runCommandForced("--create_billing_cost=\"USD 42.42\"", "--roid_suffix=Q9JYB4C", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getStandardCreateCost()).isEqualTo(Money.of(USD, 42.42));
}
@ -218,8 +220,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
"--initial_tld_state=SUNRISE",
"--roid_suffix=Q9JYB4C",
"xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getLrpTldStates())
.containsExactly(TldState.SUNRISE);
assertThat(Registry.get("xn--q9jyb4c").getLrpTldStates()).containsExactly(TldState.SUNRISE);
}
@Test
@ -272,7 +273,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
String.format("--tld_state_transitions=%s=PREDELEGATION,%s=SUNRISE", now, now.plus(1)),
"--initial_tld_state=GENERAL_AVAILABILITY",
"xn--q9jyb4c");
}
}
@Test
public void testFailure_negativeInitialRenewBillingCost() throws Exception {
@ -286,8 +287,7 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
thrown.expect(IllegalArgumentException.class);
runCommandForced(
String.format(
"--eap_fee_schedule=\"%s=JPY 123456\"",
START_OF_TIME.toString(DATETIME_FORMAT)),
"--eap_fee_schedule=\"%s=JPY 123456\"", START_OF_TIME.toString(DATETIME_FORMAT)),
"--roid_suffix=Q9JYB4C",
"xn--q9jyb4c");
}
@ -351,7 +351,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test
public void testFailure_setReservedListFromOtherTld() throws Exception {
runFailureReservedListsTest("tld_banned",
runFailureReservedListsTest(
"tld_banned",
IllegalArgumentException.class,
"The reserved list(s) tld_banned cannot be applied to the tld xn--q9jyb4c");
}
@ -363,7 +364,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test
public void testFailure_setCommonAndReservedListFromOtherTld() throws Exception {
runFailureReservedListsTest("common_abuse,tld_banned",
runFailureReservedListsTest(
"common_abuse,tld_banned",
IllegalArgumentException.class,
"The reserved list(s) tld_banned cannot be applied to the tld xn--q9jyb4c");
}
@ -381,7 +383,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test
public void testFailure_setMultipleReservedListsFromOtherTld() throws Exception {
runFailureReservedListsTest("tld_banned,soy_expurgated",
runFailureReservedListsTest(
"tld_banned,soy_expurgated",
IllegalArgumentException.class,
"The reserved list(s) tld_banned, soy_expurgated cannot be applied to the tld xn--q9jyb4c");
}
@ -393,7 +396,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
@Test
public void testFailure_setNonExistentReservedLists() throws Exception {
runFailureReservedListsTest("xn--q9jyb4c_asdf,common_asdsdgh",
runFailureReservedListsTest(
"xn--q9jyb4c_asdf,common_asdsdgh",
IllegalStateException.class,
"Could not find reserved list xn--q9jyb4c_asdf to add to the tld");
}
@ -458,7 +462,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
private void runReservedListsTestOverride(String reservedLists) throws Exception {
runCommandForced("--override_reserved_list_rules",
runCommandForced(
"--override_reserved_list_rules",
"--reserved_lists",
reservedLists,
"--roid_suffix=Q9JYB4C",
@ -466,9 +471,8 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
}
private void runFailureReservedListsTest(
String reservedLists,
Class<? extends Exception> errorClass,
String errorMsg) throws Exception {
String reservedLists, Class<? extends Exception> errorClass, String errorMsg)
throws Exception {
thrown.expect(errorClass, errorMsg);
runCommandForced("--reserved_lists", reservedLists, "--roid_suffix=Q9JYB4C", "xn--q9jyb4c");
}