diff --git a/java/google/registry/model/domain/fee/EapFee.java b/java/google/registry/model/domain/fee/EapFee.java new file mode 100644 index 000000000..8c9c751b5 --- /dev/null +++ b/java/google/registry/model/domain/fee/EapFee.java @@ -0,0 +1,51 @@ +// Copyright 2016 The Domain Registry 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.model.domain.fee; + +import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; + +import com.google.common.collect.Range; + +import org.joda.money.Money; +import org.joda.time.DateTime; + +/** + * An object representing an EAP fee (as a {@link Money}) along with the interval for which the + * fee applies. + */ +public class EapFee { + + /** The EAP fee (as applied on top of the domain registration cost). */ + Money cost; + + /** The time period for which the fee applies. */ + Range period; + + public Money getCost() { + return cost; + } + + public Range getPeriod() { + return period; + } + + public static EapFee create(Money cost, Range period) { + EapFee instance = new EapFee(); + instance.cost = checkArgumentNotNull(cost, "EAP fee cost cannot be null."); + instance.period = checkArgumentNotNull(period, "EAP fee period cannot be null."); + return instance; + } +} + diff --git a/java/google/registry/model/registry/Registry.java b/java/google/registry/model/registry/Registry.java index a56efb6e3..6f20c8706 100644 --- a/java/google/registry/model/registry/Registry.java +++ b/java/google/registry/model/registry/Registry.java @@ -23,6 +23,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION; import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; import static google.registry.util.DateTimeUtils.END_OF_TIME; +import static google.registry.util.DateTimeUtils.START_OF_TIME; import static google.registry.util.PreconditionsUtils.checkArgumentNotNull; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.joda.money.CurrencyUnit.USD; @@ -37,6 +38,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Iterables; import com.google.common.collect.Ordering; +import com.google.common.collect.Range; import com.google.common.net.InternetDomainName; import com.googlecode.objectify.Key; @@ -57,6 +59,7 @@ import google.registry.model.ImmutableObject; import google.registry.model.common.EntityGroupRoot; import google.registry.model.common.TimedTransitionProperty; import google.registry.model.common.TimedTransitionProperty.TimedTransition; +import google.registry.model.domain.fee.EapFee; import google.registry.model.pricing.PremiumPricingEngine; import google.registry.model.pricing.StaticPremiumListPricingEngine; import google.registry.model.registry.label.PremiumList; @@ -521,8 +524,15 @@ public class Registry extends ImmutableObject implements Buildable { /** * Returns the EAP fee for the registry at the given time. */ - public Money getEapFeeFor(DateTime now) { - return eapFeeSchedule.getValueAtTime(now); + public EapFee getEapFeeFor(DateTime now) { + ImmutableSortedMap valueMap = eapFeeSchedule.toValueMap(); + DateTime periodStart = valueMap.floorKey(now); + DateTime periodEnd = valueMap.ceilingKey(now); + return EapFee.create( + eapFeeSchedule.getValueAtTime(now), + Range.closedOpen( + periodStart != null ? periodStart : START_OF_TIME, + periodEnd != null ? periodEnd : END_OF_TIME)); } public String getLordnUsername() { diff --git a/javatests/google/registry/model/registry/RegistryTest.java b/javatests/google/registry/model/registry/RegistryTest.java index 0b3a6dda0..97aa900d6 100644 --- a/javatests/google/registry/model/registry/RegistryTest.java +++ b/javatests/google/registry/model/registry/RegistryTest.java @@ -416,7 +416,8 @@ public class RegistryTest extends EntityTestCase { @Test public void testEapFee_undefined() { - assertThat(Registry.get("tld").getEapFeeFor(clock.nowUtc())).isEqualTo(Money.of(USD, 0)); + assertThat(Registry.get("tld").getEapFeeFor(clock.nowUtc()).getCost()) + .isEqualTo(Money.of(USD, 0)); } @Test @@ -430,9 +431,11 @@ public class RegistryTest extends EntityTestCase { a, Money.of(USD, 100), b, Money.of(USD, 50))).build(); - assertThat(registry.getEapFeeFor(clock.nowUtc())).isEqualTo(Money.of(USD, 100)); - assertThat(registry.getEapFeeFor(clock.nowUtc().minusDays(2))).isEqualTo(Money.of(USD, 0)); - assertThat(registry.getEapFeeFor(clock.nowUtc().plusDays(2))).isEqualTo(Money.of(USD, 50)); + assertThat(registry.getEapFeeFor(clock.nowUtc()).getCost()).isEqualTo(Money.of(USD, 100)); + assertThat(registry.getEapFeeFor(clock.nowUtc().minusDays(2)).getCost()) + .isEqualTo(Money.of(USD, 0)); + assertThat(registry.getEapFeeFor(clock.nowUtc().plusDays(2)).getCost()) + .isEqualTo(Money.of(USD, 50)); } @Test diff --git a/javatests/google/registry/tools/CreateTldCommandTest.java b/javatests/google/registry/tools/CreateTldCommandTest.java index cfb238c82..7ba311799 100644 --- a/javatests/google/registry/tools/CreateTldCommandTest.java +++ b/javatests/google/registry/tools/CreateTldCommandTest.java @@ -107,9 +107,10 @@ public class CreateTldCommandTest extends CommandTestCase { "xn--q9jyb4c"); Registry registry = Registry.get("xn--q9jyb4c"); - assertThat(registry.getEapFeeFor(now.minusHours(1))).isEqualTo(Money.zero(USD)); - assertThat(registry.getEapFeeFor(now.plusHours(1))).isEqualTo(Money.of(USD, 50)); - assertThat(registry.getEapFeeFor(now.plusDays(1).plusHours(1))).isEqualTo(Money.of(USD, 10)); + 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.plusDays(1).plusHours(1)).getCost()) + .isEqualTo(Money.of(USD, 10)); } @Test