mirror of
https://github.com/google/nomulus.git
synced 2025-05-04 22:17:51 +02:00
ReferenceUnion is a hack to work around the mismatch between how we store references (by roid) and how they are represented in EPP (by foreign key). If it ever needed to exist (not entirely clear...) it should have remained tightly scoped within the domain commands and resources. Instead it has leaked everywhere in the project, causing lots of boilerplate. This CL hides all of that behind standard Refs, and should be followed by work to remove ReferenceUnion completely. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=122424416
183 lines
7.3 KiB
Java
183 lines
7.3 KiB
Java
// 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.pricing;
|
|
|
|
import static com.google.common.truth.Truth.assertThat;
|
|
import static google.registry.pricing.PricingEngineProxy.getDomainCreateCost;
|
|
import static google.registry.pricing.PricingEngineProxy.getDomainRenewCost;
|
|
import static google.registry.pricing.PricingEngineProxy.isPremiumName;
|
|
import static google.registry.testing.DatastoreHelper.createTld;
|
|
import static google.registry.testing.DatastoreHelper.persistPremiumList;
|
|
import static google.registry.testing.DatastoreHelper.persistResource;
|
|
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
|
import static org.joda.money.CurrencyUnit.USD;
|
|
|
|
import com.google.common.collect.ImmutableSortedMap;
|
|
|
|
import google.registry.model.registry.Registry;
|
|
import google.registry.model.registry.label.PremiumList;
|
|
import google.registry.testing.AppEngineRule;
|
|
import google.registry.testing.ExceptionRule;
|
|
import google.registry.testing.FakeClock;
|
|
import google.registry.util.Clock;
|
|
|
|
import org.joda.money.Money;
|
|
import org.joda.time.DateTime;
|
|
import org.junit.Before;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runners.JUnit4;
|
|
|
|
/** Tests for {@link PricingEngineProxy}. */
|
|
@RunWith(JUnit4.class)
|
|
public class PricingEngineProxyTest {
|
|
|
|
@Rule
|
|
public final ExceptionRule thrown = new ExceptionRule();
|
|
|
|
@Rule
|
|
public final AppEngineRule appEngine = AppEngineRule.builder()
|
|
.withDatastore()
|
|
.build();
|
|
|
|
private Clock clock;
|
|
|
|
@Before
|
|
public void before() throws Exception {
|
|
PremiumList premiumList = persistPremiumList(
|
|
"rich,USD 100",
|
|
"richer,USD 999",
|
|
"fraction,USD 20.50");
|
|
createTld("moka");
|
|
persistResource(Registry.get("moka").asBuilder().setPremiumList(premiumList).build());
|
|
clock = new FakeClock(DateTime.parse("2016-03-17T12:01:00Z"));
|
|
}
|
|
|
|
@Test
|
|
public void test_getDomainCreateCost_multipleYears() {
|
|
assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 1))
|
|
.isEqualTo(Money.parse("USD 13"));
|
|
assertThat(getDomainCreateCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 5))
|
|
.isEqualTo(Money.parse("USD 65"));
|
|
assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 1))
|
|
.isEqualTo(Money.parse("USD 20.50"));
|
|
assertThat(getDomainCreateCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 3))
|
|
.isEqualTo(Money.parse("USD 61.50"));
|
|
}
|
|
|
|
@Test
|
|
public void test_getDomainRenewCost_multipleYears() {
|
|
assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 1))
|
|
.isEqualTo(Money.parse("USD 11"));
|
|
assertThat(getDomainRenewCost("espresso.moka", clock.nowUtc(), "TheRegistrar", 5))
|
|
.isEqualTo(Money.parse("USD 55"));
|
|
assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 1))
|
|
.isEqualTo(Money.parse("USD 20.50"));
|
|
assertThat(getDomainRenewCost("fraction.moka", clock.nowUtc(), "TheRegistrar", 3))
|
|
.isEqualTo(Money.parse("USD 61.50"));
|
|
}
|
|
|
|
@Test
|
|
public void testIsPremiumDomain() throws Exception {
|
|
createTld("example");
|
|
assertThat(isPremiumName("poor.example", clock.nowUtc(), "TheRegistrar")).isFalse();
|
|
assertThat(isPremiumName("rich.example", clock.nowUtc(), "TheRegistrar")).isTrue();
|
|
assertThat(isPremiumName("richer.example", clock.nowUtc(), "TheRegistrar")).isTrue();
|
|
}
|
|
|
|
@Test
|
|
public void testGetDomainCreateCost() throws Exception {
|
|
// The example tld has a premium price for "rich".
|
|
createTld("example");
|
|
// The default value of 17 is set in createTld().
|
|
assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), "TheRegistrar", 1))
|
|
.isEqualTo(Money.of(USD, 13));
|
|
assertThat(getDomainCreateCost("poor.example", clock.nowUtc(), "TheRegistrar", 2))
|
|
.isEqualTo(Money.of(USD, 26));
|
|
assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), "TheRegistrar", 1))
|
|
.isEqualTo(Money.of(USD, 100));
|
|
assertThat(getDomainCreateCost("rich.example", clock.nowUtc(), "TheRegistrar", 2))
|
|
.isEqualTo(Money.of(USD, 200));
|
|
}
|
|
|
|
@Test
|
|
public void testGetDomainRenewCost() throws Exception {
|
|
// The example tld has a premium price for "rich".
|
|
createTld("example");
|
|
persistResource(
|
|
Registry.get("example")
|
|
.asBuilder()
|
|
.setRenewBillingCostTransitions(
|
|
ImmutableSortedMap.of(
|
|
START_OF_TIME, Money.of(USD, 8), clock.nowUtc(), Money.of(USD, 10)))
|
|
.build());
|
|
assertThat(getDomainRenewCost("poor.example", START_OF_TIME, "TheRegistrar", 1))
|
|
.isEqualTo(Money.of(USD, 8));
|
|
assertThat(getDomainRenewCost("poor.example", START_OF_TIME, "TheRegistrar", 2))
|
|
.isEqualTo(Money.of(USD, 16));
|
|
assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), "TheRegistrar", 1))
|
|
.isEqualTo(Money.of(USD, 10));
|
|
assertThat(getDomainRenewCost("poor.example", clock.nowUtc(), "TheRegistrar", 2))
|
|
.isEqualTo(Money.of(USD, 20));
|
|
assertThat(getDomainRenewCost("rich.example", START_OF_TIME, "TheRegistrar", 1))
|
|
.isEqualTo(Money.of(USD, 100));
|
|
assertThat(getDomainRenewCost("rich.example", START_OF_TIME, "TheRegistrar", 2))
|
|
.isEqualTo(Money.of(USD, 200));
|
|
assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), "TheRegistrar", 1))
|
|
.isEqualTo(Money.of(USD, 100));
|
|
assertThat(getDomainRenewCost("rich.example", clock.nowUtc(), "TheRegistrar", 2))
|
|
.isEqualTo(Money.of(USD, 200));
|
|
}
|
|
|
|
@Test
|
|
public void testFailure_isPremiumNameForSldNotUnderTld() {
|
|
thrown.expect(IllegalArgumentException.class);
|
|
isPremiumName("test.example", clock.nowUtc(), "TheRegistrar");
|
|
}
|
|
|
|
@Test
|
|
public void testFailure_isPremiumNameForSldSubdomain() throws Exception {
|
|
createTld("example");
|
|
thrown.expect(IllegalArgumentException.class);
|
|
isPremiumName("rich.sld.example", clock.nowUtc(), "TheRegistrar");
|
|
}
|
|
|
|
@Test
|
|
public void testFailure_getCreateCostForSldNotUnderTld() {
|
|
thrown.expect(IllegalArgumentException.class);
|
|
getDomainCreateCost("test.example", clock.nowUtc(), "TheRegistrar", 1);
|
|
}
|
|
|
|
@Test
|
|
public void testFailure_getCreateCostForSldSubdomain() throws Exception {
|
|
createTld("example");
|
|
thrown.expect(IllegalArgumentException.class);
|
|
getDomainCreateCost("rich.sld.example", clock.nowUtc(), "TheRegistrar", 1);
|
|
}
|
|
|
|
@Test
|
|
public void testFailure_getRenewCostForSldNotUnderTld() {
|
|
thrown.expect(IllegalArgumentException.class);
|
|
getDomainRenewCost("test.example", clock.nowUtc(), "TheRegistrar", 1);
|
|
}
|
|
|
|
@Test
|
|
public void testFailure_getRenewCostForSldSubdomain() throws Exception {
|
|
createTld("example");
|
|
thrown.expect(IllegalArgumentException.class);
|
|
getDomainRenewCost("rich.sld.example", clock.nowUtc(), "TheRegistrar", 1);
|
|
}
|
|
}
|