1
0
mirror of https://github.com/google/nomulus synced 2026-02-11 07:11:40 +00:00

Remove PremiumList from Datastore schema (#1256)

* Remove PremiumList from Datastore schema

* Remove commented out code

* Change lastUpdateTime to creationTimestamp

* Remove extra file

* Remove currency unit from input data to parse

* Revert extra file

* Check currency in parse

* Create all PremiumEntries before saving them in bulk

* small fixes

* Fix merge conflict
This commit is contained in:
sarahcaseybot
2021-08-10 13:26:13 -04:00
committed by GitHub
parent 9811cdb85c
commit 28a1cc613c
58 changed files with 399 additions and 713 deletions

View File

@@ -57,6 +57,7 @@ import google.registry.model.ofy.CommitLogManifest;
import google.registry.model.ofy.CommitLogMutation;
import google.registry.model.registrar.RegistrarContact;
import google.registry.model.registry.label.PremiumList;
import google.registry.model.registry.label.PremiumList.PremiumEntry;
import google.registry.model.registry.label.ReservedList;
import google.registry.model.server.Lock;
import google.registry.model.tmch.ClaimsList;
@@ -65,7 +66,6 @@ import google.registry.persistence.VKey;
import google.registry.persistence.transaction.JpaTransactionManager;
import google.registry.persistence.transaction.TransactionManagerFactory;
import google.registry.schema.replay.SqlReplayCheckpoint;
import google.registry.schema.tld.PremiumEntry;
import google.registry.testing.AppEngineExtension;
import google.registry.testing.DatabaseHelper;
import google.registry.testing.FakeClock;

View File

@@ -691,7 +691,7 @@ public class ExpandRecurringBillingEventsActionTest
persistResource(
Registry.get("tld")
.asBuilder()
.setPremiumList(persistPremiumList("tld2", "example,USD 100"))
.setPremiumList(persistPremiumList("tld2", USD, "example,USD 100"))
.build());
persistResource(recurring);
action.cursorTimeParam = Optional.of(START_OF_TIME);

View File

@@ -23,6 +23,7 @@ import static google.registry.testing.DatabaseHelper.persistResource;
import static java.nio.charset.StandardCharsets.UTF_8;
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static org.joda.money.CurrencyUnit.USD;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
@@ -54,7 +55,7 @@ public class ExportPremiumTermsActionTest {
private static final ImmutableList<String> PREMIUM_NAMES =
ImmutableList.of("2048,USD 549", "0,USD 549");
private static final String EXPECTED_FILE_CONTENT =
DISCLAIMER_WITH_NEWLINE + "0,USD 549.00\n" + "2048,USD 549.00\n";
DISCLAIMER_WITH_NEWLINE + "0, 549.00\n" + "2048, 549.00\n";
@RegisterExtension
public final AppEngineExtension appEngine =
@@ -75,7 +76,7 @@ public class ExportPremiumTermsActionTest {
@BeforeEach
void beforeEach() throws Exception {
createTld("tld");
PremiumList pl = PremiumListDao.save("pl-name", PREMIUM_NAMES);
PremiumList pl = PremiumListDao.save("pl-name", USD, PREMIUM_NAMES);
persistResource(
Registry.get("tld").asBuilder().setPremiumList(pl).setDriveFolderId("folder_id").build());
when(driveConnection.createOrUpdateFile(

View File

@@ -895,7 +895,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v06.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_response_v06.xml"));
@@ -907,7 +907,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
// The domain needs to exist in order for it to be loaded to check for restore fee.
persistActiveDomain("allowedinsunrise.tld");
@@ -922,7 +922,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v11_create.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_response_v11_create.xml"));
@@ -934,7 +934,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v11_renew.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_response_v11_renew.xml"));
@@ -946,7 +946,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v11_transfer.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_response_v11_transfer.xml"));
@@ -958,7 +958,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v11_restore.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_response_v11_restore.xml"));
@@ -970,7 +970,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
persistPendingDeleteDomain("reserved.tld");
persistPendingDeleteDomain("allowedinsunrise.tld");
@@ -987,7 +987,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v12.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_response_v12.xml"));
@@ -999,7 +999,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
// The domain needs to exist in order for it to be loaded to check for restore fee.
persistActiveDomain("allowedinsunrise.tld");
@@ -1014,7 +1014,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v06.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_sunrise_response_v06.xml"));
@@ -1028,7 +1028,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
persistPendingDeleteDomain("reserved.tld");
persistPendingDeleteDomain("allowedinsunrise.tld");
@@ -1046,7 +1046,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v11_create.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_sunrise_response_v11_create.xml"));
@@ -1059,7 +1059,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v11_renew.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_sunrise_response_v11_renew.xml"));
@@ -1072,7 +1072,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v11_transfer.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_sunrise_response_v11_transfer.xml"));
@@ -1085,7 +1085,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v11_restore.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_sunrise_response_v11_restore.xml"));
@@ -1098,7 +1098,7 @@ class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFlow, Dom
Registry.get("tld")
.asBuilder()
.setReservedLists(createReservedList())
.setPremiumList(persistPremiumList("tld", "premiumcollision,USD 70"))
.setPremiumList(persistPremiumList("tld", USD, "premiumcollision,USD 70"))
.build());
setEppInput("domain_check_fee_reserved_v12.xml");
runFlowAssertResponse(loadFile("domain_check_fee_reserved_sunrise_response_v12.xml"));

View File

@@ -64,7 +64,7 @@ public final class OteAccountBuilderTest {
@BeforeEach
void beforeEach() {
persistPremiumList("default_sandbox_list", "sandbox,USD 1000");
persistPremiumList("default_sandbox_list", USD, "sandbox,USD 1000");
}
private void assertTldExists(String tld, TldState tldState, Money eapFee) {

View File

@@ -23,6 +23,7 @@ import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static google.registry.testing.DatabaseHelper.persistResource;
import static google.registry.testing.TestDataHelper.loadBytes;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
import static org.joda.money.CurrencyUnit.USD;
import google.registry.model.domain.DomainHistory;
import google.registry.model.eppcommon.Trid;
@@ -77,7 +78,7 @@ public final class OteStatsTestHelper {
*/
public static void setupIncompleteOte(String baseClientId) throws IOException {
createTld("tld");
persistPremiumList("default_sandbox_list", "sandbox,USD 1000");
persistPremiumList("default_sandbox_list", USD, "sandbox,USD 1000");
OteAccountBuilder.forClientId(baseClientId).addContact("email@example.com").buildAndPersist();
String oteAccount1 = String.format("%s-1", baseClientId);
DateTime now = DateTime.now(DateTimeZone.UTC);

View File

@@ -71,7 +71,7 @@ public final class RegistryTest extends EntityTestCase {
@TestOfyAndSql
void testPersistence_updateReservedAndPremiumListSuccessfully() {
ReservedList rl15 = persistReservedList("tld-reserved15", "potato,FULLY_BLOCKED");
PremiumList pl = persistPremiumList("tld2", "lol,USD 50", "cat,USD 700");
PremiumList pl = persistPremiumList("tld2", USD, "lol,USD 50", "cat,USD 700");
Registry registry =
Registry.get("tld").asBuilder().setReservedLists(rl15).setPremiumList(pl).build();
tm().transact(() -> tm().put(registry));
@@ -145,7 +145,7 @@ public final class RegistryTest extends EntityTestCase {
.setReservedListMapFromLines(
ImmutableList.of("potato,FULLY_BLOCKED", "phone,FULLY_BLOCKED"))
.setShouldPublish(true)
.setLastUpdateTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
ReservedList rl16 =
persistReservedList(
@@ -154,7 +154,7 @@ public final class RegistryTest extends EntityTestCase {
.setReservedListMapFromLines(
ImmutableList.of("port,FULLY_BLOCKED", "manteau,FULLY_BLOCKED"))
.setShouldPublish(true)
.setLastUpdateTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
Registry registry1 =
newRegistry("propter", "PROPTER")
@@ -197,7 +197,7 @@ public final class RegistryTest extends EntityTestCase {
.setReservedListMapFromLines(
ImmutableList.of("potato,FULLY_BLOCKED", "phone,FULLY_BLOCKED"))
.setShouldPublish(true)
.setLastUpdateTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
ReservedList rl6 =
persistReservedList(
@@ -206,7 +206,7 @@ public final class RegistryTest extends EntityTestCase {
.setReservedListMapFromLines(
ImmutableList.of("port,FULLY_BLOCKED", "manteau,FULLY_BLOCKED"))
.setShouldPublish(true)
.setLastUpdateTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
Registry r =
Registry.get("tld").asBuilder().setReservedLists(ImmutableSet.of(rl5, rl6)).build();
@@ -223,7 +223,7 @@ public final class RegistryTest extends EntityTestCase {
.setReservedListMapFromLines(
ImmutableList.of("potato,FULLY_BLOCKED", "phone,FULLY_BLOCKED"))
.setShouldPublish(true)
.setLastUpdateTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
persistReservedList(
new ReservedList.Builder()
@@ -231,7 +231,7 @@ public final class RegistryTest extends EntityTestCase {
.setReservedListMapFromLines(
ImmutableList.of("port,FULLY_BLOCKED", "manteau,FULLY_BLOCKED"))
.setShouldPublish(true)
.setLastUpdateTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
Registry r =
Registry.get("tld")
@@ -245,7 +245,7 @@ public final class RegistryTest extends EntityTestCase {
@TestOfyAndSql
void testSetPremiumList() {
PremiumList pl2 = persistPremiumList("tld2", "lol,USD 50", "cat,USD 700");
PremiumList pl2 = persistPremiumList("tld2", USD, "lol,USD 50", "cat,USD 700");
Registry registry = Registry.get("tld").asBuilder().setPremiumList(pl2).build();
Optional<String> pl = registry.getPremiumListName();
assertThat(pl).hasValue("tld2");

View File

@@ -27,7 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList;
import com.google.common.hash.BloomFilter;
import google.registry.model.registry.Registry;
import google.registry.model.registry.label.PremiumList.PremiumListEntry;
import google.registry.model.registry.label.PremiumList.PremiumEntry;
import google.registry.schema.tld.PremiumListDao;
import google.registry.testing.AppEngineExtension;
import java.math.BigDecimal;
@@ -48,11 +48,7 @@ public class PremiumListTest {
createTld("tld");
PremiumList pl =
persistPremiumList(
"tld",
"lol,USD 999 # yup",
"rich,USD 1999 #tada",
"icann,JPY 100",
"johnny-be-goode,USD 20.50");
"tld", USD, "lol, 999", "rich, 1999", "icann, 100", "johnny-be-goode, 20.50");
persistResource(Registry.get("tld").asBuilder().setPremiumList(pl).build());
}
@@ -60,7 +56,7 @@ public class PremiumListTest {
void testSave_badSyntax() {
assertThrows(
IllegalArgumentException.class,
() -> persistPremiumList("gtld1", "lol,nonsense USD,e,e # yup"));
() -> persistPremiumList("gtld1", USD, "lol,nonsense USD,e,e # yup"));
}
@Test
@@ -102,14 +98,21 @@ public class PremiumListTest {
"List 'tld' cannot contain duplicate labels. Dupes (with counts) were: [lol x 2]");
}
@Test
void testParse_canIncludeOrNotIncludeCurrencyUnit() {
PremiumListDao.save("tld", USD, ImmutableList.of("rofl,USD 90", "paper, 80"));
assertThat(PremiumListDao.getPremiumPrice("tld", "rofl").get()).isEqualTo(Money.of(USD, 90));
assertThat(PremiumListDao.getPremiumPrice("tld", "paper").get()).isEqualTo(Money.of(USD, 80));
}
@Test
void testValidation_labelMustBeLowercase() {
Exception e =
assertThrows(
IllegalArgumentException.class,
() ->
new PremiumListEntry.Builder()
.setPrice(Money.parse("USD 399"))
new PremiumEntry.Builder()
.setPrice(BigDecimal.valueOf(399))
.setLabel("UPPER.tld")
.build());
assertThat(e).hasMessageThat().contains("must be in puny-coded, lower-case form");
@@ -121,8 +124,8 @@ public class PremiumListTest {
assertThrows(
IllegalArgumentException.class,
() ->
new PremiumListEntry.Builder()
.setPrice(Money.parse("USD 399"))
new PremiumEntry.Builder()
.setPrice(BigDecimal.valueOf(399))
.setLabel("lower.みんな")
.build());
assertThat(e).hasMessageThat().contains("must be in puny-coded, lower-case form");

View File

@@ -57,7 +57,7 @@ public class ReservedListDaoTest {
testReservedList =
new ReservedList.Builder()
.setName("testlist")
.setLastUpdateTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.setShouldPublish(false)
.setReservedListMap(testReservations)
.build();
@@ -76,7 +76,7 @@ public class ReservedListDaoTest {
.getSingleResult();
assertThat(persistedList.getReservedListEntries())
.containsExactlyEntriesIn(testReservations);
assertThat(persistedList.getLastUpdateTime()).isEqualTo(fakeClock.nowUtc());
assertThat(persistedList.getCreationTimestamp()).isEqualTo(fakeClock.nowUtc());
});
}
@@ -108,7 +108,7 @@ public class ReservedListDaoTest {
ReservedListDao.save(testReservedList);
ReservedList persistedList = ReservedListDao.getLatestRevision("testlist").get();
assertThat(persistedList.getRevisionId()).isNotNull();
assertThat(persistedList.getLastUpdateTime()).isEqualTo(fakeClock.nowUtc());
assertThat(persistedList.getCreationTimestamp()).isEqualTo(fakeClock.nowUtc());
assertThat(persistedList.getName()).isEqualTo("testlist");
assertThat(persistedList.getShouldPublish()).isFalse();
assertThat(persistedList.getReservedListEntries()).containsExactlyEntriesIn(testReservations);
@@ -119,7 +119,7 @@ public class ReservedListDaoTest {
ReservedListDao.save(
new ReservedList.Builder()
.setName("testlist")
.setLastUpdateTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.setShouldPublish(false)
.setReservedListMap(
ImmutableMap.of(
@@ -130,7 +130,7 @@ public class ReservedListDaoTest {
ReservedListDao.save(testReservedList);
ReservedList persistedList = ReservedListDao.getLatestRevision("testlist").get();
assertThat(persistedList.getRevisionId()).isNotNull();
assertThat(persistedList.getLastUpdateTime()).isEqualTo(fakeClock.nowUtc());
assertThat(persistedList.getCreationTimestamp()).isEqualTo(fakeClock.nowUtc());
assertThat(persistedList.getName()).isEqualTo("testlist");
assertThat(persistedList.getShouldPublish()).isFalse();
assertThat(persistedList.getReservedListEntries()).containsExactlyEntriesIn(testReservations);

View File

@@ -35,7 +35,7 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import google.registry.model.ofy.Ofy;
import google.registry.model.registry.Registry;
import google.registry.schema.tld.PremiumEntry;
import google.registry.model.registry.label.PremiumList.PremiumEntry;
import google.registry.testing.AppEngineExtension;
import google.registry.testing.FakeClock;
import google.registry.testing.InjectExtension;
@@ -255,17 +255,17 @@ class ReservedListTest {
assertThat(reservedList.getReservedListEntries()).hasSize(3);
ReservedListEntry trombone = reservedList.getReservedListEntries().get("trombone");
assertThat(trombone.label).isEqualTo("trombone");
assertThat(trombone.domainLabel).isEqualTo("trombone");
assertThat(trombone.reservationType).isEqualTo(FULLY_BLOCKED);
assertThat(trombone.comment).isEqualTo("yup");
ReservedListEntry oysters = reservedList.getReservedListEntries().get("oysters");
assertThat(oysters.label).isEqualTo("oysters");
assertThat(oysters.domainLabel).isEqualTo("oysters");
assertThat(oysters.reservationType).isEqualTo(FULLY_BLOCKED);
assertThat(oysters.comment).isEqualTo("this is a loooong comment");
ReservedListEntry nullComment = reservedList.getReservedListEntries().get("nullcomment");
assertThat(nullComment.label).isEqualTo("nullcomment");
assertThat(nullComment.domainLabel).isEqualTo("nullcomment");
assertThat(nullComment.reservationType).isEqualTo(ALLOWED_IN_SUNRISE);
assertThat(nullComment.comment).isEmpty();
}
@@ -299,8 +299,7 @@ class ReservedListTest {
ReservedList original = persistReservedList("tld-reserved-cloning", "trombone,FULLY_BLOCKED");
ReservedList clone = original.asBuilder().build();
assertThat(clone.getName()).isEqualTo("tld-reserved-cloning");
assertThat(clone.creationTime).isEqualTo(original.creationTime);
assertThat(clone.lastUpdateTime).isEqualTo(original.lastUpdateTime);
assertThat(clone.creationTimestamp).isEqualTo(original.creationTimestamp);
assertThat(clone.parent).isEqualTo(original.parent);
assertThat(original.getReservedListEntries()).isEqualTo(clone.getReservedListEntries());
}

View File

@@ -1,90 +0,0 @@
// Copyright 2020 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.persistence.converter;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import com.googlecode.objectify.Key;
import google.registry.model.ImmutableObject;
import google.registry.model.registry.label.PremiumList;
import google.registry.testing.AppEngineExtension;
import javax.persistence.Entity;
import javax.persistence.Id;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link PremiumListKeyConverter}. */
class PremiumListKeyConverterTest {
@RegisterExtension
final AppEngineExtension appEngine =
AppEngineExtension.builder()
.withDatastoreAndCloudSql()
.withJpaUnitTestEntities(PremiumListEntity.class)
.build();
private final PremiumListKeyConverter converter = new PremiumListKeyConverter();
@Test
void convertToDatabaseColumn_returnsNullIfInputIsNull() {
assertThat(converter.convertToDatabaseColumn(null)).isNull();
}
@Test
void convertToDatabaseColumn_convertsCorrectly() {
assertThat(
converter.convertToDatabaseColumn(
Key.create(getCrossTldKey(), PremiumList.class, "testList")))
.isEqualTo("testList");
}
@Test
void convertToEntityAttribute_returnsNullIfInputIsNull() {
assertThat(converter.convertToEntityAttribute(null)).isNull();
}
@Test
void convertToEntityAttribute_convertsCorrectly() {
assertThat(converter.convertToEntityAttribute("testList"))
.isEqualTo(Key.create(getCrossTldKey(), PremiumList.class, "testList"));
}
@Test
void testRoundTrip() {
Key<PremiumList> key = Key.create(getCrossTldKey(), PremiumList.class, "test");
PremiumListEntity testEntity = new PremiumListEntity(key);
jpaTm().transact(() -> jpaTm().insert(testEntity));
PremiumListEntity persisted =
jpaTm().transact(() -> jpaTm().getEntityManager().find(PremiumListEntity.class, "test"));
assertThat(persisted.premiumList).isEqualTo(key);
}
@Entity(name = "PremiumListEntity")
private static class PremiumListEntity extends ImmutableObject {
@Id String name;
Key<PremiumList> premiumList;
public PremiumListEntity() {}
PremiumListEntity(Key<PremiumList> premiumList) {
this.name = premiumList.getName();
this.premiumList = premiumList;
}
}
}

View File

@@ -49,7 +49,8 @@ public class PricingEngineProxyTest {
@BeforeEach
void beforeEach() {
PremiumList premiumList =
persistPremiumList("rich,USD 100", "richer,USD 999", "fraction,USD 20.50");
persistPremiumList(
"premium list", USD, "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"));

View File

@@ -76,7 +76,7 @@ public class PremiumListDaoTest {
.setName("testname")
.setCurrency(USD)
.setLabelsToPrices(TEST_PRICES)
.setCreationTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build();
}
@@ -90,7 +90,7 @@ public class PremiumListDaoTest {
assertThat(persistedListOpt).isPresent();
PremiumList persistedList = persistedListOpt.get();
assertThat(persistedList.getLabelsToPrices()).containsExactlyEntriesIn(TEST_PRICES);
assertThat(persistedList.getCreationTime()).isEqualTo(fakeClock.nowUtc());
assertThat(persistedList.getCreationTimestamp()).isEqualTo(fakeClock.nowUtc());
});
}
@@ -112,7 +112,7 @@ public class PremiumListDaoTest {
BigDecimal.valueOf(0.01),
"silver",
BigDecimal.valueOf(30.03)))
.setCreationTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
jpaTm()
.transact(
@@ -129,9 +129,8 @@ public class PremiumListDaoTest {
BigDecimal.valueOf(0.01),
"silver",
BigDecimal.valueOf(30.03)));
assertThat(savedList.getCreationTime()).isEqualTo(fakeClock.nowUtc());
assertThat(savedList.getCreationTimestamp()).isEqualTo(fakeClock.nowUtc());
assertThat(savedList.getRevisionId()).isGreaterThan(firstRevisionId);
assertThat(savedList.getCreationTime()).isEqualTo(fakeClock.nowUtc());
});
}
@@ -154,14 +153,14 @@ public class PremiumListDaoTest {
.setName("list1")
.setCurrency(USD)
.setLabelsToPrices(ImmutableMap.of("wrong", BigDecimal.valueOf(1000.50)))
.setCreationTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
PremiumListDao.save(
new PremiumList.Builder()
.setName("list1")
.setCurrency(USD)
.setLabelsToPrices(TEST_PRICES)
.setCreationTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
jpaTm()
.transact(
@@ -182,7 +181,7 @@ public class PremiumListDaoTest {
.setName("list1")
.setCurrency(JPY)
.setLabelsToPrices(TEST_PRICES)
.setCreationTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
jpaTm()
.transact(
@@ -207,7 +206,7 @@ public class PremiumListDaoTest {
.setName("premlist")
.setCurrency(USD)
.setLabelsToPrices(TEST_PRICES)
.setCreationTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
persistResource(
newRegistry("foobar", "FOOBAR").asBuilder().setPremiumList(premiumList).build());
@@ -231,7 +230,7 @@ public class PremiumListDaoTest {
BigDecimal.valueOf(1000.0),
"palladium",
BigDecimal.valueOf(15000)))
.setCreationTime(fakeClock.nowUtc())
.setCreationTimestamp(fakeClock.nowUtc())
.build());
persistResource(
newRegistry("foobar", "FOOBAR").asBuilder().setPremiumList(premiumList).build());
@@ -247,7 +246,7 @@ public class PremiumListDaoTest {
PremiumListDao.save(testList);
PremiumList pl = PremiumListDao.getLatestRevision("testname").get();
assertThat(PremiumListDao.premiumListCache.getIfPresent("testname").get()).isEqualTo(pl);
transactIfJpaTm(() -> PremiumListDao.save("testname", ImmutableList.of("test,USD 1")));
transactIfJpaTm(() -> PremiumListDao.save("testname", USD, ImmutableList.of("test,USD 1")));
assertThat(PremiumListDao.premiumListCache.getIfPresent("testname")).isNull();
}

View File

@@ -16,6 +16,7 @@ package google.registry.schema.tld;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.schema.tld.PremiumListUtils.parseToPremiumList;
import static org.joda.money.CurrencyUnit.USD;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList;
@@ -36,7 +37,7 @@ class PremiumListUtilsTest {
void parseInputToPremiumList_works() {
PremiumList premiumList =
parseToPremiumList(
"testlist", ImmutableList.of("foo,USD 99.50", "bar,USD 30", "baz,USD 10"));
"testlist", USD, ImmutableList.of("foo,USD 99.50", "bar,USD 30", "baz,USD 10"));
assertThat(premiumList.getName()).isEqualTo("testlist");
assertThat(premiumList.getLabelsToPrices())
.containsExactly("foo", twoDigits(99.50), "bar", twoDigits(30), "baz", twoDigits(10));
@@ -49,10 +50,10 @@ class PremiumListUtilsTest {
IllegalArgumentException.class,
() ->
parseToPremiumList(
"testlist", ImmutableList.of("foo,USD 99.50", "bar,USD 30", "baz,JPY 990")));
assertThat(thrown)
.hasMessageThat()
.isEqualTo("The Cloud SQL schema requires exactly one currency, but got: [JPY, USD]");
"testlist",
USD,
ImmutableList.of("foo,USD 99.50", "bar,USD 30", "baz,JPY 990")));
assertThat(thrown).hasMessageThat().isEqualTo("The currency unit must be USD");
}
private static BigDecimal twoDigits(double num) {

View File

@@ -24,6 +24,7 @@ import static google.registry.testing.DatabaseHelper.newDomainBase;
import static google.registry.testing.DatabaseHelper.persistActiveHost;
import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.money.CurrencyUnit.USD;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -61,7 +62,7 @@ public enum Fixture {
createTlds("xn--q9jyb4c", "example");
// Used for OT&E TLDs
persistPremiumList("default_sandbox_list", "sandbox,USD 1000");
persistPremiumList("default_sandbox_list", USD, "sandbox,USD 1000");
try {
OteStatsTestHelper.setupCompleteOte("otefinished");

View File

@@ -101,7 +101,7 @@ import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
import google.registry.model.registry.Registry.TldType;
import google.registry.model.registry.label.PremiumList;
import google.registry.model.registry.label.PremiumList.PremiumListEntry;
import google.registry.model.registry.label.PremiumList.PremiumEntry;
import google.registry.model.registry.label.ReservedList;
import google.registry.model.registry.label.ReservedListDao;
import google.registry.model.reporting.HistoryEntry;
@@ -264,7 +264,7 @@ public class DatabaseHelper {
.setRestoreBillingCost(Money.of(USD, 17))
.setServerStatusChangeBillingCost(Money.of(USD, 19))
// Always set a default premium list. Tests that don't want it can delete it.
.setPremiumList(persistPremiumList(tld, DEFAULT_PREMIUM_LIST_CONTENTS.get()))
.setPremiumList(persistPremiumList(tld, USD, DEFAULT_PREMIUM_LIST_CONTENTS.get()))
.setPremiumPricingEngine(StaticPremiumListPricingEngine.NAME)
.setDnsWriters(ImmutableSet.of(VoidDnsWriter.NAME))
.build();
@@ -361,7 +361,7 @@ public class DatabaseHelper {
.setName(listName)
.setReservedListMapFromLines(ImmutableList.copyOf(lines))
.setShouldPublish(shouldPublish)
.setLastUpdateTime(DateTime.now(DateTimeZone.UTC))
.setCreationTimestamp(DateTime.now(DateTimeZone.UTC))
.build();
return persistReservedList(reservedList);
}
@@ -374,29 +374,27 @@ public class DatabaseHelper {
* incrementing FakeClock for all tests in order to persist the commit logs properly because of
* the requirement to have monotonically increasing timestamps.
*/
public static PremiumList persistPremiumList(String listName, String... lines) {
public static PremiumList persistPremiumList(
String listName, CurrencyUnit currencyUnit, String... lines) {
checkState(lines.length != 0, "Must provide at least one premium entry");
PremiumList partialPremiumList = new PremiumList.Builder().setName(listName).build();
ImmutableMap<String, PremiumListEntry> entries = partialPremiumList.parse(asList(lines));
CurrencyUnit currencyUnit =
entries.entrySet().iterator().next().getValue().getValue().getCurrencyUnit();
ImmutableMap<String, PremiumEntry> entries = partialPremiumList.parse(asList(lines));
PremiumList premiumList =
partialPremiumList
.asBuilder()
.setCreationTime(DateTime.now(DateTimeZone.UTC))
.setCreationTimestamp(DateTime.now(DateTimeZone.UTC))
.setCurrency(currencyUnit)
.setLabelsToPrices(
entries.entrySet().stream()
.collect(
toImmutableMap(
Map.Entry::getKey, entry -> entry.getValue().getValue().getAmount())))
toImmutableMap(Map.Entry::getKey, entry -> entry.getValue().getValue())))
.build();
// Since we used to persist a PremiumList to Datastore here, it is necessary to allocate an ID
// here to prevent breaking some of the hard-coded flow tests. IDs in tests are allocated in a
// strictly increasing sequence, if we don't pad out the ID here, we would have to renumber
// hundreds of unit tests.
allocateId();
jpaTm().transact(() -> jpaTm().insert(premiumList));
PremiumListDao.save(premiumList);
maybeAdvanceClock();
return premiumList;
}
@@ -1245,11 +1243,10 @@ public class DatabaseHelper {
return result;
}
/** Returns the entire map of {@link PremiumListEntry}s for the given {@link PremiumList}. */
public static ImmutableMap<String, PremiumListEntry> loadPremiumListEntries(
PremiumList premiumList) {
return Streams.stream(PremiumListDao.loadAllPremiumListEntries(premiumList.getName()))
.collect(toImmutableMap(PremiumListEntry::getLabel, Function.identity()));
/** Returns the entire map of {@link PremiumEntry}s for the given {@link PremiumList}. */
public static ImmutableMap<String, PremiumEntry> loadPremiumEntries(PremiumList premiumList) {
return Streams.stream(PremiumListDao.loadAllPremiumEntries(premiumList.getName()))
.collect(toImmutableMap(PremiumEntry::getDomainLabel, Function.identity()));
}
/** Loads and returns the registrar with the given client ID, or throws IAE if not present. */

View File

@@ -17,6 +17,7 @@ package google.registry.tools;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.money.CurrencyUnit.JPY;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
@@ -76,7 +77,7 @@ class CreateAnchorTenantCommandTest extends EppToolCommandTestCase<CreateAnchorT
persistResource(
Registry.get("tld")
.asBuilder()
.setPremiumList(persistPremiumList("tld", "premium,JPY 20000"))
.setPremiumList(persistPremiumList("tld", JPY, "premium,JPY 20000"))
.build());
runCommandForced("--client=NewRegistrar", "--superuser", "--fee",
"--reason=anchor-tenant-test", "--contact=jd1234", "--domain_name=premium.tld");

View File

@@ -19,6 +19,7 @@ import static google.registry.persistence.transaction.TransactionManagerFactory.
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.money.CurrencyUnit.JPY;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException;
@@ -121,7 +122,7 @@ class CreateDomainCommandTest extends EppToolCommandTestCase<CreateDomainCommand
@Test
void testSuccess_premiumJpyDomain() throws Exception {
createTld("baar");
persistPremiumList("baar", "parajiumu,JPY 96083");
persistPremiumList("baar", JPY, "parajiumu,JPY 96083");
persistResource(
Registry.get("baar")
.asBuilder()

View File

@@ -32,6 +32,7 @@ import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldType;
import java.io.File;
import java.io.IOException;
import org.joda.money.CurrencyUnit;
import org.junit.jupiter.api.BeforeEach;
/** Base class for common testing setup for create and update commands for Premium Lists. */
@@ -51,7 +52,7 @@ abstract class CreateOrUpdatePremiumListCommandTestCase<T extends CreateOrUpdate
premiumTermsPath = premiumTermsFile.getPath();
}
Registry createRegistry(String tldStr, String premiumListInput) {
Registry createRegistry(String tldStr, CurrencyUnit currency, String premiumListInput) {
Registry registry;
if (premiumListInput != null) {
registry =
@@ -60,7 +61,7 @@ abstract class CreateOrUpdatePremiumListCommandTestCase<T extends CreateOrUpdate
Ascii.toUpperCase(tldStr),
ImmutableSortedMap.of(START_OF_TIME, GENERAL_AVAILABILITY),
TldType.TEST);
persistPremiumList(tldStr, premiumListInput);
persistPremiumList(tldStr, currency, premiumListInput);
persistResource(registry);
} else {
registry =

View File

@@ -107,7 +107,7 @@ abstract class CreateOrUpdateReservedListCommandTestCase<
ImmutableMap<String, ReservedListEntry> labelsToEntries) {
return new ReservedList.Builder()
.setName(name)
.setLastUpdateTime(creationTime)
.setCreationTimestamp(creationTime)
.setShouldPublish(shouldPublish)
.setReservedListMap(labelsToEntries)
.build();

View File

@@ -33,7 +33,7 @@ class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
@BeforeEach
void beforeEach() {
registry = createRegistry(TLD_TEST, null);
registry = createRegistry(TLD_TEST, null, null);
}
@Test
@@ -45,7 +45,7 @@ class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
@Test
void commandRun_successCreateList() throws Exception {
runCommandForced("--name=" + TLD_TEST, "--input=" + premiumTermsPath);
runCommandForced("--name=" + TLD_TEST, "--input=" + premiumTermsPath, "--currency=USD");
assertThat(registry.getTld().toString()).isEqualTo(TLD_TEST);
assertThat(PremiumListDao.getLatestRevision(TLD_TEST).isPresent()).isTrue();
}
@@ -53,50 +53,52 @@ class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
@Test
// since the old entity is always null and file cannot be empty, the prompt will NOT be "No entity
// changes to apply."
void commandInit_successStageNewEntity() throws Exception {
void commandPrompt_successStageNewEntity() throws Exception {
CreatePremiumListCommand command = new CreatePremiumListCommand();
command.inputFile = Paths.get(premiumTermsPath);
command.init();
assertThat(command.prompt()).contains("Create PremiumList@");
assertThat(command.prompt()).contains(String.format("name=%s", TLD_TEST));
command.currencyUnit = "USD";
command.prompt();
assertThat(command.prompt()).isEqualTo("Create new premium list for prime?");
}
@Test
void commandInit_successStageNewEntityWithOverride() throws Exception {
void commandPrompt_successStageNewEntityWithOverride() throws Exception {
CreatePremiumListCommand command = new CreatePremiumListCommand();
String alterTld = "override";
command.inputFile = Paths.get(premiumTermsPath);
command.override = true;
command.name = alterTld;
command.init();
assertThat(command.prompt()).contains("Create PremiumList@");
assertThat(command.prompt()).contains(String.format("name=%s", alterTld));
command.currencyUnit = "USD";
command.prompt();
assertThat(command.prompt()).isEqualTo("Create new premium list for override?");
}
@Test
void commandInit_failureNoInputFile() {
void commandPrompt_failureNoInputFile() {
CreatePremiumListCommand command = new CreatePremiumListCommand();
assertThrows(NullPointerException.class, command::init);
assertThrows(NullPointerException.class, command::prompt);
}
@Test
void commandInit_failurePremiumListAlreadyExists() {
void commandPrompt_failurePremiumListAlreadyExists() {
String randomStr = "random";
createTld(randomStr);
CreatePremiumListCommand command = new CreatePremiumListCommand();
command.name = randomStr;
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::init);
command.currencyUnit = "USD";
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
assertThat(thrown).hasMessageThat().isEqualTo("A premium list already exists by this name");
}
@Test
void commandInit_failureMismatchedTldFileName_noOverride() throws Exception {
void commandPrompt_failureMismatchedTldFileName_noOverride() throws Exception {
CreatePremiumListCommand command = new CreatePremiumListCommand();
String fileName = "random";
Path tmpPath = tmpDir.resolve(String.format("%s.txt", fileName));
Files.write(new byte[0], tmpPath.toFile());
command.inputFile = tmpPath;
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::init);
command.currencyUnit = "USD";
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
assertThat(thrown)
.hasMessageThat()
.contains(
@@ -108,11 +110,12 @@ class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
}
@Test
void commandInit_failureMismatchedTldName_noOverride() {
void commandPrompt_failureMismatchedTldName_noOverride() {
CreatePremiumListCommand command = new CreatePremiumListCommand();
String fileName = "random";
command.name = fileName;
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::init);
command.currencyUnit = "USD";
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
assertThat(thrown)
.hasMessageThat()
.contains(
@@ -122,18 +125,4 @@ class CreatePremiumListCommandTest<C extends CreatePremiumListCommand>
+ "yet TLD %s does not exist",
fileName));
}
@Test
void commandInit_failureUseEmptyFile() throws Exception {
CreatePremiumListCommand command = new CreatePremiumListCommand();
String fileName = "empty";
Path tmpPath = tmpDir.resolve(String.format("%s.txt", fileName));
Files.write(new byte[0], tmpPath.toFile());
command.inputFile = tmpPath;
command.name = TLD_TEST;
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::init);
assertThat(thrown)
.hasMessageThat()
.contains("The Cloud SQL schema requires exactly one currency");
}
}

View File

@@ -49,7 +49,7 @@ class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
persistReservedList("xn--q9jyb4c_abuse", "lamb,FULLY_BLOCKED");
persistReservedList("tld_banned", "kilo,FULLY_BLOCKED", "lima,FULLY_BLOCKED");
persistReservedList("soy_expurgated", "fireflies,FULLY_BLOCKED");
persistPremiumList("xn--q9jyb4c", "minecraft,USD 1000");
persistPremiumList("xn--q9jyb4c", USD, "minecraft,USD 1000");
command.validDnsWriterNames = ImmutableSet.of("VoidDnsWriter", "FooDnsWriter");
}

View File

@@ -17,9 +17,10 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.loadPremiumListEntries;
import static google.registry.testing.DatabaseHelper.loadPremiumEntries;
import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.money.CurrencyUnit.USD;
import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.model.registry.Registry;
@@ -32,8 +33,8 @@ class DeletePremiumListCommandTest extends CommandTestCase<DeletePremiumListComm
@Test
void testSuccess() throws Exception {
PremiumList premiumList = persistPremiumList("xn--q9jyb4c", "blah,USD 100");
assertThat(loadPremiumListEntries(premiumList)).hasSize(1);
PremiumList premiumList = persistPremiumList("xn--q9jyb4c", USD, "blah,USD 100");
assertThat(loadPremiumEntries(premiumList)).hasSize(1);
runCommand("--force", "--name=xn--q9jyb4c");
assertThat(PremiumListDao.getLatestRevision("xn--q9jyb4c")).isEmpty();
}
@@ -49,7 +50,7 @@ class DeletePremiumListCommandTest extends CommandTestCase<DeletePremiumListComm
@Test
void testFailure_whenPremiumListIsInUse() {
PremiumList premiumList = persistPremiumList("xn--q9jyb4c", "blah,USD 100");
PremiumList premiumList = persistPremiumList("xn--q9jyb4c", USD, "blah,USD 100");
createTld("xn--q9jyb4c");
persistResource(Registry.get("xn--q9jyb4c").asBuilder().setPremiumList(premiumList).build());
IllegalArgumentException thrown =

View File

@@ -24,6 +24,7 @@ import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.loadRegistrar;
import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static google.registry.testing.DatabaseHelper.persistResource;
import static org.joda.money.CurrencyUnit.USD;
import static org.joda.time.DateTimeZone.UTC;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -39,7 +40,6 @@ import google.registry.testing.DeterministicStringGenerator;
import google.registry.testing.FakeClock;
import google.registry.util.CidrAddressBlock;
import java.security.cert.CertificateParsingException;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.joda.time.Duration;
@@ -58,7 +58,7 @@ class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
void beforeEach() {
command.passwordGenerator = passwordGenerator;
command.clock = new FakeClock(DateTime.parse("2018-07-07TZ"));
persistPremiumList("default_sandbox_list", "sandbox,USD 1000");
persistPremiumList("default_sandbox_list", USD, "sandbox,USD 1000");
}
/** Verify TLD creation. */
@@ -79,17 +79,17 @@ class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
ImmutableSortedMap<DateTime, Money> eapFeeSchedule = registry.getEapFeeScheduleAsMap();
if (!isEarlyAccess) {
assertThat(eapFeeSchedule)
.isEqualTo(ImmutableSortedMap.of(new DateTime(0), Money.of(CurrencyUnit.USD, 0)));
.isEqualTo(ImmutableSortedMap.of(new DateTime(0), Money.of(USD, 0)));
} else {
assertThat(eapFeeSchedule)
.isEqualTo(
ImmutableSortedMap.of(
new DateTime(0),
Money.of(CurrencyUnit.USD, 0),
Money.of(USD, 0),
DateTime.parse("2018-03-01T00:00:00Z"),
Money.of(CurrencyUnit.USD, 100),
Money.of(USD, 100),
DateTime.parse("2030-03-01T00:00:00Z"),
Money.of(CurrencyUnit.USD, 0)));
Money.of(USD, 0)));
}
}

View File

@@ -16,15 +16,18 @@ package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.joda.money.CurrencyUnit.USD;
import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Files;
import google.registry.model.registry.Registry;
import google.registry.model.registry.label.PremiumList;
import google.registry.schema.tld.PremiumListDao;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -35,40 +38,32 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
@BeforeEach
void beforeEach() {
registry = createRegistry(TLD_TEST, initialPremiumListData);
registry = createRegistry(TLD_TEST, USD, initialPremiumListData);
}
@Test
void verify_registryIsSetUpCorrectly() {
Optional<PremiumList> list = PremiumListDao.getLatestRevision(TLD_TEST);
// ensure that no premium list is created before running the command
assertThat(PremiumListDao.getLatestRevision(TLD_TEST).isPresent()).isTrue();
assertThat(list.isPresent()).isTrue();
// ensure that there's value in existing premium list;
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
ImmutableSet<String> entries = command.getExistingPremiumListEntry(TLD_TEST);
ImmutableSet<String> entries = command.getExistingPremiumEntry(list.get());
assertThat(entries.size()).isEqualTo(1);
// data from @beforeEach of CreateOrUpdatePremiumListCommandTestCase.java
assertThat(entries.contains("doge,USD 9090.00")).isTrue();
}
@Test
void commandInit_successStageNoEntityChange() throws Exception {
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.inputFile = Paths.get(premiumTermsPath);
command.name = TLD_TEST;
command.init();
assertThat(command.prompt()).contains("No entity changes to apply.");
}
@Test
void commandInit_successStageEntityChange() throws Exception {
void commandPrompt_successStageEntityChange() throws Exception {
File tmpFile = tmpDir.resolve(String.format("%s.txt", TLD_TEST)).toFile();
String newPremiumListData = "omg,JPY 1234";
String newPremiumListData = "omg,USD 1234";
Files.asCharSink(tmpFile, UTF_8).write(newPremiumListData);
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.inputFile = Paths.get(tmpFile.getPath());
command.name = TLD_TEST;
command.init();
assertThat(command.prompt()).contains("Update PremiumList@");
command.prompt();
assertThat(command.prompt()).contains("Update premium list for prime?");
}
@Test
@@ -82,7 +77,8 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
command.inputFile = Paths.get(tmpFile.getPath());
runCommandForced("--name=" + TLD_TEST, "--input=" + command.inputFile);
ImmutableSet<String> entries = command.getExistingPremiumListEntry(TLD_TEST);
ImmutableSet<String> entries =
command.getExistingPremiumEntry(PremiumListDao.getLatestRevision(TLD_TEST).get());
assertThat(entries.size()).isEqualTo(1);
// verify that list is updated; cannot use only string since price is formatted;
assertThat(entries.contains("eth,USD 9999.00")).isTrue();
@@ -99,7 +95,8 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
runCommandForced("--name=" + TLD_TEST, "--input=" + command.inputFile);
// assert all three lines from premiumTerms are added
ImmutableSet<String> entries = command.getExistingPremiumListEntry(TLD_TEST);
ImmutableSet<String> entries =
command.getExistingPremiumEntry(PremiumListDao.getLatestRevision(TLD_TEST).get());
assertThat(entries.size()).isEqualTo(3);
assertThat(entries.contains("foo,USD 9000.00")).isTrue();
assertThat(entries.contains("doge,USD 100.00")).isTrue();
@@ -107,26 +104,24 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
}
@Test
void commandInit_failureUpdateEmptyList() throws Exception {
void commandPrompt_failureUpdateEmptyList() throws Exception {
Path tmpPath = tmpDir.resolve(String.format("%s.txt", TLD_TEST));
Files.write(new byte[0], tmpPath.toFile());
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.inputFile = tmpPath;
command.name = TLD_TEST;
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::init);
assertThat(thrown)
.hasMessageThat()
.contains("The Cloud SQL schema requires exactly one currency");
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
assertThat(thrown).hasMessageThat().contains("Input cannot be empty");
}
@Test
void commandInit_failureNoPreviousVersion() {
void commandPrompt_failureNoPreviousVersion() {
String fileName = "random";
registry = createRegistry(fileName, null);
registry = createRegistry(fileName, null, null);
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.name = fileName;
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::init);
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
@@ -134,17 +129,17 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
}
@Test
void commandInit_failureNoInputFile() {
void commandPrompt_failureNoInputFile() {
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
assertThrows(NullPointerException.class, command::init);
assertThrows(NullPointerException.class, command::prompt);
}
@Test
void commandInit_failureTldFromNameDoesNotExist() {
void commandPrompt_failureTldFromNameDoesNotExist() {
String fileName = "random";
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
command.name = fileName;
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::init);
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
assertThat(thrown)
.hasMessageThat()
.isEqualTo(
@@ -152,13 +147,13 @@ class UpdatePremiumListCommandTest<C extends UpdatePremiumListCommand>
}
@Test
void commandInit_failureTldFromInputFileDoesNotExist() {
void commandPrompt_failureTldFromInputFileDoesNotExist() {
String fileName = "random";
UpdatePremiumListCommand command = new UpdatePremiumListCommand();
// using tld extracted from file name but this tld is not part of the registry
command.inputFile =
Paths.get(tmpDir.resolve(String.format("%s.txt", fileName)).toFile().getPath());
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::init);
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, command::prompt);
assertThat(thrown)
.hasMessageThat()
.isEqualTo(

View File

@@ -48,8 +48,7 @@ class UpdateReservedListCommandTest
new ReservedList.Builder()
.setName("xn--q9jyb4c_common-reserved")
.setReservedListMapFromLines(ImmutableList.of("helicopter,FULLY_BLOCKED"))
.setCreationTime(START_OF_TIME)
.setLastUpdateTime(START_OF_TIME)
.setCreationTimestamp(START_OF_TIME)
.setShouldPublish(shouldPublish)
.build());
}

View File

@@ -54,7 +54,7 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
persistReservedList("xn--q9jyb4c_abuse", "lamb,FULLY_BLOCKED");
persistReservedList("tld_banned", "kilo,FULLY_BLOCKED", "lima,FULLY_BLOCKED");
persistReservedList("soy_expurgated", "fireflies,FULLY_BLOCKED");
persistPremiumList("xn--q9jyb4c", "minecraft,USD 1000");
persistPremiumList("xn--q9jyb4c", USD, "minecraft,USD 1000");
persistReservedList("xn--q9jyb4c_r1", "foo,FULLY_BLOCKED");
persistReservedList("xn--q9jyb4c_r2", "moop,FULLY_BLOCKED");
createTld("xn--q9jyb4c");

View File

@@ -17,8 +17,9 @@ package google.registry.tools.server;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.testing.DatabaseHelper.createTlds;
import static google.registry.testing.DatabaseHelper.loadPremiumListEntries;
import static google.registry.testing.DatabaseHelper.loadPremiumEntries;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static org.joda.money.CurrencyUnit.USD;
import google.registry.model.registry.label.PremiumList;
import google.registry.schema.tld.PremiumListDao;
@@ -86,20 +87,21 @@ public class CreatePremiumListActionTest {
action.name = "zanzibar";
action.inputData = "zanzibar,USD 100";
action.override = true;
action.currency = USD;
action.run();
assertThat(response.getStatus()).isEqualTo(SC_OK);
assertThat(loadPremiumListEntries(PremiumListDao.getLatestRevision("zanzibar").get()))
.hasSize(1);
assertThat(loadPremiumEntries(PremiumListDao.getLatestRevision("zanzibar").get())).hasSize(1);
}
@Test
void test_success() {
action.name = "foo";
action.inputData = "rich,USD 25\nricher,USD 1000\n";
action.currency = USD;
action.run();
assertThat(response.getStatus()).isEqualTo(SC_OK);
PremiumList premiumList = PremiumListDao.getLatestRevision("foo").get();
assertThat(loadPremiumListEntries(premiumList)).hasSize(2);
assertThat(loadPremiumEntries(premiumList)).hasSize(2);
assertThat(PremiumListDao.getPremiumPrice(premiumList.getName(), "rich"))
.hasValue(Money.parse("USD 25"));
assertThat(PremiumListDao.getPremiumPrice(premiumList.getName(), "diamond")).isEmpty();

View File

@@ -15,6 +15,8 @@
package google.registry.tools.server;
import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static org.joda.money.CurrencyUnit.JPY;
import static org.joda.money.CurrencyUnit.USD;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
@@ -27,8 +29,8 @@ class ListPremiumListsActionTest extends ListActionTestCase {
@BeforeEach
void beforeEach() {
persistPremiumList("xn--q9jyb4c", "rich,USD 100");
persistPremiumList("how", "richer,JPY 5000");
persistPremiumList("xn--q9jyb4c", USD, "rich,USD 100");
persistPremiumList("how", JPY, "richer,JPY 5000");
action = new ListPremiumListsAction();
}

View File

@@ -17,9 +17,10 @@ package google.registry.tools.server;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.testing.DatabaseHelper.createTlds;
import static google.registry.testing.DatabaseHelper.loadPremiumListEntries;
import static google.registry.testing.DatabaseHelper.loadPremiumEntries;
import static google.registry.util.ResourceUtils.readResourceUtf8;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static org.joda.money.CurrencyUnit.USD;
import com.google.common.base.Splitter;
import com.google.common.truth.Truth8;
@@ -79,12 +80,12 @@ class UpdatePremiumListActionTest {
.omitEmptyStrings()
.splitToList(
readResourceUtf8(DatabaseHelper.class, "default_premium_list_testdata.csv"));
PremiumListDao.save("foo", inputLines);
PremiumListDao.save("foo", USD, inputLines);
action.name = "foo";
action.inputData = "rich,USD 75\nricher,USD 5000\npoor, USD 0.99";
action.run();
assertThat(response.getStatus()).isEqualTo(SC_OK);
assertThat(loadPremiumListEntries(PremiumListDao.getLatestRevision("foo").get())).hasSize(3);
assertThat(loadPremiumEntries(PremiumListDao.getLatestRevision("foo").get())).hasSize(3);
Truth8.assertThat(PremiumListDao.getPremiumPrice("foo", "rich"))
.hasValue(Money.parse("USD 75"));
Truth8.assertThat(PremiumListDao.getPremiumPrice("foo", "richer"))

View File

@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.registrar.Registrar.loadByClientId;
import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static javax.servlet.http.HttpServletResponse.SC_MOVED_TEMPORARILY;
import static org.joda.money.CurrencyUnit.USD;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -78,7 +79,7 @@ public final class ConsoleOteSetupActionTest {
@BeforeEach
void beforeEach() throws Exception {
persistPremiumList("default_sandbox_list", "sandbox,USD 1000");
persistPremiumList("default_sandbox_list", USD, "sandbox,USD 1000");
action.req = request;
action.method = Method.GET;

View File

@@ -20,6 +20,7 @@ import static google.registry.model.common.GaeUserIdConverter.convertEmailAddres
import static google.registry.model.registrar.Registrar.loadByClientId;
import static google.registry.testing.DatabaseHelper.persistPremiumList;
import static javax.servlet.http.HttpServletResponse.SC_MOVED_TEMPORARILY;
import static org.joda.money.CurrencyUnit.USD;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -81,7 +82,7 @@ final class ConsoleRegistrarCreatorActionTest {
@BeforeEach
void beforeEach() throws Exception {
persistPremiumList("default_sandbox_list", "sandbox,USD 1000");
persistPremiumList("default_sandbox_list", USD, "sandbox,USD 1000");
action.req = request;
action.method = Method.GET;
@@ -198,8 +199,7 @@ final class ConsoleRegistrarCreatorActionTest {
Registrar registrar = loadByClientId("myclientid").orElse(null);
assertThat(registrar).isNotNull();
assertThat(registrar.getClientId()).isEqualTo("myclientid");
assertThat(registrar.getBillingAccountMap())
.containsExactly(CurrencyUnit.USD, "billing-account");
assertThat(registrar.getBillingAccountMap()).containsExactly(USD, "billing-account");
assertThat(registrar.getDriveFolderId()).isEqualTo("drive-id");
assertThat(registrar.getIanaIdentifier()).isEqualTo(12321L);
@@ -296,9 +296,12 @@ final class ConsoleRegistrarCreatorActionTest {
assertThat(registrar).isNotNull();
assertThat(registrar.getBillingAccountMap())
.containsExactly(
CurrencyUnit.JPY, "billing-account-yen",
CurrencyUnit.USD, "billing-account-usd",
CurrencyUnit.EUR, "billing-account-eur");
CurrencyUnit.JPY,
"billing-account-yen",
USD,
"billing-account-usd",
CurrencyUnit.EUR,
"billing-account-eur");
}
@TestOfyAndSql

View File

@@ -15,9 +15,6 @@ LastSqlTransaction
Modification
OneTime
PollMessage
PremiumList
PremiumListEntry
PremiumListRevision
RdeRevision
Recurring
Registrar

View File

@@ -2,9 +2,6 @@ ClaimsList
ClaimsListSingleton
Cursor
DatabaseMigrationStateSchedule
PremiumList
PremiumListEntry
PremiumListRevision
Registrar
RegistrarContact
Registry

View File

@@ -11,9 +11,6 @@ HostResource
Modification
OneTime
PollMessage
PremiumList
PremiumListEntry
PremiumListRevision
Recurring
Registrar
RegistrarContact

View File

@@ -711,24 +711,6 @@ enum google.registry.model.registry.Registry$TldType {
REAL;
TEST;
}
class google.registry.model.registry.label.PremiumList {
@Id java.lang.String name;
@Parent com.googlecode.objectify.Key<google.registry.model.common.EntityGroupRoot> parent;
com.googlecode.objectify.Key<google.registry.model.registry.label.PremiumList$PremiumListRevision> revisionKey;
org.joda.time.DateTime creationTime;
org.joda.time.DateTime lastUpdateTime;
}
class google.registry.model.registry.label.PremiumList$PremiumListEntry {
@Id java.lang.String label;
@Parent com.googlecode.objectify.Key<google.registry.model.registry.label.PremiumList$PremiumListRevision> parent;
java.lang.String comment;
org.joda.money.Money price;
}
class google.registry.model.registry.label.PremiumList$PremiumListRevision {
@Id long revisionId;
@Parent com.googlecode.objectify.Key<google.registry.model.registry.label.PremiumList> parent;
com.google.common.hash.BloomFilter<java.lang.String> probablePremiumLabels;
}
enum google.registry.model.registry.label.ReservationType {
ALLOWED_IN_SUNRISE;
FULLY_BLOCKED;
@@ -741,11 +723,10 @@ class google.registry.model.registry.label.ReservedList {
@Parent com.googlecode.objectify.Key<google.registry.model.common.EntityGroupRoot> parent;
boolean shouldPublish;
java.util.Map<java.lang.String, google.registry.model.registry.label.ReservedList$ReservedListEntry> reservedListMap;
org.joda.time.DateTime creationTime;
org.joda.time.DateTime lastUpdateTime;
org.joda.time.DateTime creationTimestamp;
}
class google.registry.model.registry.label.ReservedList$ReservedListEntry {
@Id java.lang.String label;
@Id java.lang.String domainLabel;
google.registry.model.registry.label.ReservationType reservationType;
java.lang.Long revisionId;
java.lang.String comment;