Remove old DomainList fields from Registry (#1231)

* Remove old DomainList fields from Registry

I also resaved all Registry objects in sandbox and production to make sure that the new field is populated on all entity objects.

* small fixes

* Some more small fixes

* Delete commented out code

* Remove existence check in tests
This commit is contained in:
sarahcaseybot 2021-07-08 17:19:11 -04:00 committed by GitHub
parent f5d344d5c9
commit d283cf1c90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 79 additions and 152 deletions

View file

@ -113,7 +113,7 @@ public class ExportPremiumTermsAction implements Runnable {
"Skipping premium terms export for TLD %s because Drive folder isn't specified", tld); "Skipping premium terms export for TLD %s because Drive folder isn't specified", tld);
return Optional.of("Skipping export because no Drive folder is associated with this TLD"); return Optional.of("Skipping export because no Drive folder is associated with this TLD");
} }
if (!registry.getPremiumList().isPresent()) { if (!registry.getPremiumListName().isPresent()) {
logger.atInfo().log("No premium terms to export for TLD %s", tld); logger.atInfo().log("No premium terms to export for TLD %s", tld);
return Optional.of("No premium lists configured"); return Optional.of("No premium lists configured");
} }
@ -137,8 +137,8 @@ public class ExportPremiumTermsAction implements Runnable {
} }
private String getFormattedPremiumTerms(Registry registry) { private String getFormattedPremiumTerms(Registry registry) {
checkState(registry.getPremiumList().isPresent(), "%s does not have a premium list", tld); checkState(registry.getPremiumListName().isPresent(), "%s does not have a premium list", tld);
String premiumListName = registry.getPremiumList().get().getName(); String premiumListName = registry.getPremiumListName().get();
checkState( checkState(
PremiumListDao.getLatestRevision(premiumListName).isPresent(), PremiumListDao.getLatestRevision(premiumListName).isPresent(),
"Could not load premium list for " + tld); "Could not load premium list for " + tld);

View file

@ -63,7 +63,7 @@ public class ExportReservedTermsAction implements Runnable {
try { try {
Registry registry = Registry.get(tld); Registry registry = Registry.get(tld);
String resultMsg; String resultMsg;
if (registry.getReservedLists().isEmpty() && isNullOrEmpty(registry.getDriveFolderId())) { if (registry.getReservedListNames().isEmpty() && isNullOrEmpty(registry.getDriveFolderId())) {
resultMsg = "No reserved lists configured"; resultMsg = "No reserved lists configured";
logger.atInfo().log("No reserved terms to export for TLD %s", tld); logger.atInfo().log("No reserved terms to export for TLD %s", tld);
} else if (registry.getDriveFolderId() == null) { } else if (registry.getDriveFolderId() == null) {

View file

@ -15,11 +15,11 @@
package google.registry.export; package google.registry.export;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.googlecode.objectify.Key;
import google.registry.config.RegistryConfig.Config; import google.registry.config.RegistryConfig.Config;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.label.ReservedList; import google.registry.model.registry.label.ReservedList;
import google.registry.model.registry.label.ReservedList.ReservedListEntry; import google.registry.model.registry.label.ReservedList.ReservedListEntry;
import google.registry.model.registry.label.ReservedListDao;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import javax.inject.Inject; import javax.inject.Inject;
@ -39,8 +39,13 @@ public final class ExportUtils {
public String exportReservedTerms(Registry registry) { public String exportReservedTerms(Registry registry) {
StringBuilder termsBuilder = new StringBuilder(reservedTermsExportDisclaimer).append("\n"); StringBuilder termsBuilder = new StringBuilder(reservedTermsExportDisclaimer).append("\n");
Set<String> reservedTerms = new TreeSet<>(); Set<String> reservedTerms = new TreeSet<>();
for (Key<ReservedList> key : registry.getReservedLists()) { for (String reservedListName : registry.getReservedListNames()) {
ReservedList reservedList = ReservedList.load(key).get(); ReservedList reservedList =
ReservedListDao.getLatestRevision(reservedListName)
.orElseThrow(
() ->
new IllegalStateException(
String.format("Reserved list %s does not exist", reservedListName)));
if (reservedList.getShouldPublish()) { if (reservedList.getShouldPublish()) {
for (ReservedListEntry entry : reservedList.getReservedListEntries().values()) { for (ReservedListEntry entry : reservedList.getReservedListEntries().values()) {
reservedTerms.add(entry.getLabel()); reservedTerms.add(entry.getLabel());

View file

@ -39,9 +39,7 @@ public final class StaticPremiumListPricingEngine implements PremiumPricingEngin
String label = InternetDomainName.from(fullyQualifiedDomainName).parts().get(0); String label = InternetDomainName.from(fullyQualifiedDomainName).parts().get(0);
Registry registry = Registry.get(checkNotNull(tld, "tld")); Registry registry = Registry.get(checkNotNull(tld, "tld"));
Optional<Money> premiumPrice = Optional<Money> premiumPrice =
registry registry.getPremiumListName().flatMap(pl -> PremiumListDao.getPremiumPrice(pl, label));
.getPremiumList()
.flatMap(listKey -> PremiumListDao.getPremiumPrice(listKey.getName(), label));
return DomainPrices.create( return DomainPrices.create(
premiumPrice.isPresent(), premiumPrice.isPresent(),
premiumPrice.orElse(registry.getStandardCreateCost()), premiumPrice.orElse(registry.getStandardCreateCost()),

View file

@ -47,7 +47,6 @@ import com.googlecode.objectify.annotation.Embed;
import com.googlecode.objectify.annotation.Entity; import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id; import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Mapify; import com.googlecode.objectify.annotation.Mapify;
import com.googlecode.objectify.annotation.OnLoad;
import com.googlecode.objectify.annotation.OnSave; import com.googlecode.objectify.annotation.OnSave;
import com.googlecode.objectify.annotation.Parent; import com.googlecode.objectify.annotation.Parent;
import google.registry.model.Buildable; import google.registry.model.Buildable;
@ -112,26 +111,6 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd
@PostLoad @PostLoad
void postLoad() { void postLoad() {
tldStr = tldStrId; tldStr = tldStrId;
// TODO(sarahbot@): Remove the rest of this method after this data migration is complete
if (premiumListName != null) {
premiumList = Key.create(getCrossTldKey(), PremiumList.class, premiumListName);
}
if (reservedListNames != null) {
reservedLists =
reservedListNames.stream()
.map(name -> Key.create(getCrossTldKey(), ReservedList.class, name))
.collect(toImmutableSet());
}
}
// TODO(sarahbot@): Remove this method after this data migration is complete
@OnLoad
void onLoad() {
if (reservedLists != null) {
reservedListNames =
reservedLists.stream().map(key -> key.getName()).collect(toImmutableSet());
}
premiumListName = premiumList == null ? null : premiumList.getName();
} }
/** The suffix that identifies roids as belonging to this specific tld, e.g. -HOW for .how. */ /** The suffix that identifies roids as belonging to this specific tld, e.g. -HOW for .how. */
@ -408,9 +387,6 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd
@Column(nullable = false) @Column(nullable = false)
CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null); CreateAutoTimestamp creationTime = CreateAutoTimestamp.create(null);
/** The set of reserved lists that are applicable to this registry. */
@Transient Set<Key<ReservedList>> reservedLists;
/** The set of reserved list names that are applicable to this registry. */ /** The set of reserved list names that are applicable to this registry. */
@Column(name = "reserved_list_names") @Column(name = "reserved_list_names")
Set<String> reservedListNames; Set<String> reservedListNames;
@ -423,13 +399,10 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd
* for a registry, the database should be queried for the entity with this name that has the * for a registry, the database should be queried for the entity with this name that has the
* largest revision ID. * largest revision ID.
*/ */
public ImmutableSet<Key<ReservedList>> getReservedLists() { public ImmutableSet<String> getReservedListNames() {
return nullToEmptyImmutableCopy(reservedLists); return nullToEmptyImmutableCopy(reservedListNames);
} }
/** The static {@link PremiumList} for this TLD, if there is one. */
@Transient Key<PremiumList> premiumList;
/** /**
* The name of the {@link PremiumList} for this TLD, if there is one. * The name of the {@link PremiumList} for this TLD, if there is one.
* *
@ -647,8 +620,8 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd
return anchorTenantAddGracePeriodLength; return anchorTenantAddGracePeriodLength;
} }
public Optional<Key<PremiumList>> getPremiumList() { public Optional<String> getPremiumListName() {
return Optional.ofNullable(premiumList); return Optional.ofNullable(premiumListName);
} }
public CurrencyUnit getCurrency() { public CurrencyUnit getCurrency() {
@ -919,26 +892,15 @@ public class Registry extends ImmutableObject implements Buildable, DatastoreAnd
public Builder setReservedLists(Set<ReservedList> reservedLists) { public Builder setReservedLists(Set<ReservedList> reservedLists) {
checkArgumentNotNull(reservedLists, "reservedLists must not be null"); checkArgumentNotNull(reservedLists, "reservedLists must not be null");
ImmutableSet.Builder<Key<ReservedList>> builder = new ImmutableSet.Builder<>();
ImmutableSet.Builder<String> nameBuilder = new ImmutableSet.Builder<>(); ImmutableSet.Builder<String> nameBuilder = new ImmutableSet.Builder<>();
for (ReservedList reservedList : reservedLists) { for (ReservedList reservedList : reservedLists) {
builder.add(Key.create(reservedList));
nameBuilder.add(reservedList.getName()); nameBuilder.add(reservedList.getName());
} }
getInstance().reservedLists = builder.build();
getInstance().reservedListNames = nameBuilder.build(); getInstance().reservedListNames = nameBuilder.build();
return this; return this;
} }
public Builder setPremiumList(@Nullable PremiumList premiumList) { public Builder setPremiumList(@Nullable PremiumList premiumList) {
getInstance().premiumList = (premiumList == null) ? null : Key.create(premiumList);
getInstance().premiumListName = (premiumList == null) ? null : premiumList.getName();
return this;
}
@VisibleForTesting
public Builder setPremiumListKey(@Nullable Key<PremiumList> premiumList) {
getInstance().premiumList = premiumList;
getInstance().premiumListName = (premiumList == null) ? null : premiumList.getName(); getInstance().premiumListName = (premiumList == null) ? null : premiumList.getName();
return this; return this;
} }

View file

@ -171,6 +171,7 @@ public abstract class BaseDomainLabelList<T extends Comparable<?>, R extends Dom
.collect(toImmutableSet()); .collect(toImmutableSet());
} }
// TODO(b/193043636): Refactor this class to no longer use key references
protected abstract boolean refersToKey( protected abstract boolean refersToKey(
Registry registry, Key<? extends BaseDomainLabelList<?, ?>> key); Registry registry, Key<? extends BaseDomainLabelList<?, ?>> key);

View file

@ -283,7 +283,7 @@ public final class PremiumList extends BaseDomainLabelList<Money, PremiumList.Pr
@Override @Override
public boolean refersToKey(Registry registry, Key<? extends BaseDomainLabelList<?, ?>> key) { public boolean refersToKey(Registry registry, Key<? extends BaseDomainLabelList<?, ?>> key) {
return Objects.equals(registry.getPremiumList().orElse(null), key); return Objects.equals(registry.getPremiumListName().orElse(null), key.getName());
} }
@Override @Override

View file

@ -20,7 +20,6 @@ import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.ImmutableMap.toImmutableMap; import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static google.registry.config.RegistryConfig.getDomainLabelListCacheDuration; import static google.registry.config.RegistryConfig.getDomainLabelListCacheDuration;
import static google.registry.model.ImmutableObject.Insignificant;
import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED; import static google.registry.model.registry.label.ReservationType.FULLY_BLOCKED;
import static google.registry.persistence.transaction.QueryComposer.Comparator.EQ; import static google.registry.persistence.transaction.QueryComposer.Comparator.EQ;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
@ -187,7 +186,7 @@ public final class ReservedList
@Override @Override
protected boolean refersToKey(Registry registry, Key<? extends BaseDomainLabelList<?, ?>> key) { protected boolean refersToKey(Registry registry, Key<? extends BaseDomainLabelList<?, ?>> key) {
return registry.getReservedLists().contains(key); return registry.getReservedListNames().contains(key.getName());
} }
/** Determines whether the ReservedList is in use on any Registry */ /** Determines whether the ReservedList is in use on any Registry */
@ -236,11 +235,6 @@ public final class ReservedList
return getFromCache(listName, cache); return getFromCache(listName, cache);
} }
/** Loads a ReservedList from its Objectify key. */
public static Optional<ReservedList> load(Key<ReservedList> key) {
return get(key.getName());
}
/** /**
* Queries the set of all reserved lists associated with the specified TLD and returns the * Queries the set of all reserved lists associated with the specified TLD and returns the
* reservation types of the label. * reservation types of the label.
@ -270,7 +264,7 @@ public final class ReservedList
new ImmutableSet.Builder<>(); new ImmutableSet.Builder<>();
// Loop through all reservation lists and add each of them. // Loop through all reservation lists and add each of them.
for (ReservedList rl : loadReservedLists(registry.getReservedLists())) { for (ReservedList rl : loadReservedLists(registry.getReservedListNames())) {
if (rl.getReservedListEntries().containsKey(label)) { if (rl.getReservedListEntries().containsKey(label)) {
ReservedListEntry entry = rl.getReservedListEntries().get(label); ReservedListEntry entry = rl.getReservedListEntries().get(label);
entriesBuilder.add(entry); entriesBuilder.add(entry);
@ -285,17 +279,15 @@ public final class ReservedList
} }
private static ImmutableSet<ReservedList> loadReservedLists( private static ImmutableSet<ReservedList> loadReservedLists(
ImmutableSet<Key<ReservedList>> reservedListKeys) { ImmutableSet<String> reservedListNames) {
return reservedListKeys return reservedListNames.stream()
.stream()
.map( .map(
(listKey) -> { (listName) -> {
try { try {
return cache.get(listKey.getName()); return cache.get(listName);
} catch (ExecutionException e) { } catch (ExecutionException e) {
throw new UncheckedExecutionException( throw new UncheckedExecutionException(
String.format( String.format("Could not load the reserved list '%s' from the cache", listName),
"Could not load the reserved list '%s' from the cache", listKey.getName()),
e); e);
} }
}) })

View file

@ -15,7 +15,6 @@
package google.registry.tools; package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static com.google.common.collect.Sets.difference; import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.intersection; import static com.google.common.collect.Sets.intersection;
import static com.google.common.collect.Sets.union; import static com.google.common.collect.Sets.union;
@ -26,7 +25,6 @@ import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters; import com.beust.jcommander.Parameters;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.googlecode.objectify.Key;
import google.registry.config.RegistryEnvironment; import google.registry.config.RegistryEnvironment;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState; import google.registry.model.registry.Registry.TldState;
@ -113,7 +111,7 @@ class UpdateTldCommand extends CreateOrUpdateTldCommand {
ImmutableSet<String> getReservedLists(Registry oldRegistry) { ImmutableSet<String> getReservedLists(Registry oldRegistry) {
return formUpdatedList( return formUpdatedList(
"reserved lists", "reserved lists",
oldRegistry.getReservedLists().stream().map(Key::getName).collect(toImmutableSet()), oldRegistry.getReservedListNames(),
reservedListNames, reservedListNames,
reservedListsAdd, reservedListsAdd,
reservedListsRemove); reservedListsRemove);

View file

@ -70,8 +70,7 @@ public final class OteAccountBuilderTest {
private void assertTldExists(String tld, TldState tldState, Money eapFee) { private void assertTldExists(String tld, TldState tldState, Money eapFee) {
Registry registry = Registry.get(tld); Registry registry = Registry.get(tld);
assertThat(registry).isNotNull(); assertThat(registry).isNotNull();
assertThat(registry.getPremiumList()).isPresent(); assertThat(registry.getPremiumListName()).hasValue("default_sandbox_list");
assertThat(registry.getPremiumList().get().getName()).isEqualTo("default_sandbox_list");
assertThat(registry.getTldStateTransitions()).containsExactly(START_OF_TIME, tldState); assertThat(registry.getTldStateTransitions()).containsExactly(START_OF_TIME, tldState);
assertThat(registry.getDnsWriters()).containsExactly("VoidDnsWriter"); assertThat(registry.getDnsWriters()).containsExactly("VoidDnsWriter");
assertThat(registry.getAddGracePeriodLength()).isEqualTo(Duration.standardHours(1)); assertThat(registry.getAddGracePeriodLength()).isEqualTo(Duration.standardHours(1));

View file

@ -36,7 +36,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import com.googlecode.objectify.Key;
import google.registry.dns.writer.VoidDnsWriter; import google.registry.dns.writer.VoidDnsWriter;
import google.registry.model.EntityTestCase; import google.registry.model.EntityTestCase;
import google.registry.model.registry.Registry.RegistryNotFoundException; import google.registry.model.registry.Registry.RegistryNotFoundException;
@ -162,18 +161,18 @@ public final class RegistryTest extends EntityTestCase {
.asBuilder() .asBuilder()
.setReservedLists(ImmutableSet.of(rl15)) .setReservedLists(ImmutableSet.of(rl15))
.build(); .build();
assertThat(registry1.getReservedLists()).hasSize(1); assertThat(registry1.getReservedListNames()).hasSize(1);
Registry registry2 = Registry registry2 =
registry1.asBuilder().setReservedLists(ImmutableSet.of(rl15, rl16)).build(); registry1.asBuilder().setReservedLists(ImmutableSet.of(rl15, rl16)).build();
assertThat(registry1.getReservedLists()).hasSize(1); assertThat(registry1.getReservedListNames()).hasSize(1);
assertThat(registry2.getReservedLists()).hasSize(2); assertThat(registry2.getReservedListNames()).hasSize(2);
} }
@TestOfyAndSql @TestOfyAndSql
void testGetReservedLists_doesntReturnNullWhenUninitialized() { void testGetReservedLists_doesntReturnNullWhenUninitialized() {
Registry registry = newRegistry("foo", "FOO"); Registry registry = newRegistry("foo", "FOO");
assertThat(registry.getReservedLists()).isNotNull(); assertThat(registry.getReservedListNames()).isNotNull();
assertThat(registry.getReservedLists()).isEmpty(); assertThat(registry.getReservedListNames()).isEmpty();
} }
@TestOfyAndSql @TestOfyAndSql
@ -211,10 +210,9 @@ public final class RegistryTest extends EntityTestCase {
.build()); .build());
Registry r = Registry r =
Registry.get("tld").asBuilder().setReservedLists(ImmutableSet.of(rl5, rl6)).build(); Registry.get("tld").asBuilder().setReservedLists(ImmutableSet.of(rl5, rl6)).build();
assertThat(r.getReservedLists().stream().map(Key::getName)) assertThat(r.getReservedListNames()).containsExactly("tld-reserved5", "tld-reserved6");
.containsExactly("tld-reserved5", "tld-reserved6");
r = Registry.get("tld").asBuilder().setReservedLists(ImmutableSet.of()).build(); r = Registry.get("tld").asBuilder().setReservedLists(ImmutableSet.of()).build();
assertThat(r.getReservedLists()).isEmpty(); assertThat(r.getReservedListNames()).isEmpty();
} }
@TestOfyAndSql @TestOfyAndSql
@ -240,19 +238,18 @@ public final class RegistryTest extends EntityTestCase {
.asBuilder() .asBuilder()
.setReservedListsByName(ImmutableSet.of("tld-reserved15", "tld-reserved16")) .setReservedListsByName(ImmutableSet.of("tld-reserved15", "tld-reserved16"))
.build(); .build();
assertThat(r.getReservedLists().stream().map(Key::getName)) assertThat(r.getReservedListNames()).containsExactly("tld-reserved15", "tld-reserved16");
.containsExactly("tld-reserved15", "tld-reserved16");
r = Registry.get("tld").asBuilder().setReservedListsByName(ImmutableSet.of()).build(); r = Registry.get("tld").asBuilder().setReservedListsByName(ImmutableSet.of()).build();
assertThat(r.getReservedLists()).isEmpty(); assertThat(r.getReservedListNames()).isEmpty();
} }
@TestOfyAndSql @TestOfyAndSql
void testSetPremiumList() { void testSetPremiumList() {
PremiumList pl2 = persistPremiumList("tld2", "lol,USD 50", "cat,USD 700"); PremiumList pl2 = persistPremiumList("tld2", "lol,USD 50", "cat,USD 700");
Registry registry = Registry.get("tld").asBuilder().setPremiumList(pl2).build(); Registry registry = Registry.get("tld").asBuilder().setPremiumList(pl2).build();
Optional<Key<PremiumList>> plKey = registry.getPremiumList(); Optional<String> pl = registry.getPremiumListName();
assertThat(plKey).isPresent(); assertThat(pl).hasValue("tld2");
PremiumList stored = PremiumListDao.getLatestRevision(plKey.get().getName()).get(); PremiumList stored = PremiumListDao.getLatestRevision(pl.get()).get();
assertThat(stored.getName()).isEqualTo("tld2"); assertThat(stored.getName()).isEqualTo("tld2");
} }

View file

@ -86,7 +86,7 @@ class ReservedListTest {
@Test @Test
void testGetReservationTypes_allLabelsAreUnreserved_withNoReservedLists() { void testGetReservationTypes_allLabelsAreUnreserved_withNoReservedLists() {
assertThat(Registry.get("tld").getReservedLists()).isEmpty(); assertThat(Registry.get("tld").getReservedListNames()).isEmpty();
assertThat(getReservationTypes("doodle", "tld")).isEmpty(); assertThat(getReservationTypes("doodle", "tld")).isEmpty();
assertThat(getReservationTypes("access", "tld")).isEmpty(); assertThat(getReservationTypes("access", "tld")).isEmpty();
assertThat(getReservationTypes("rich", "tld")).isEmpty(); assertThat(getReservationTypes("rich", "tld")).isEmpty();

View file

@ -16,7 +16,6 @@ package google.registry.schema.tld;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat; import static com.google.common.truth.Truth8.assertThat;
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm; import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerUtil.transactIfJpaTm; import static google.registry.persistence.transaction.TransactionManagerUtil.transactIfJpaTm;
import static google.registry.testing.DatabaseHelper.newRegistry; import static google.registry.testing.DatabaseHelper.newRegistry;
@ -27,7 +26,6 @@ import static org.joda.time.Duration.standardDays;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.googlecode.objectify.Key;
import google.registry.model.registry.label.PremiumList; import google.registry.model.registry.label.PremiumList;
import google.registry.testing.AppEngineExtension; import google.registry.testing.AppEngineExtension;
import google.registry.testing.FakeClock; import google.registry.testing.FakeClock;
@ -203,22 +201,16 @@ public class PremiumListDaoTest {
@Test @Test
void getPremiumPrice_worksSuccessfully() { void getPremiumPrice_worksSuccessfully() {
PremiumList premiumList =
PremiumListDao.save(
new PremiumList.Builder()
.setName("premlist")
.setCurrency(USD)
.setLabelsToPrices(TEST_PRICES)
.setCreationTime(fakeClock.nowUtc())
.build());
persistResource( persistResource(
newRegistry("foobar", "FOOBAR") newRegistry("foobar", "FOOBAR").asBuilder().setPremiumList(premiumList).build());
.asBuilder()
.setPremiumListKey(
Key.create(
getCrossTldKey(),
google.registry.model.registry.label.PremiumList.class,
"premlist"))
.build());
PremiumListDao.save(
new PremiumList.Builder()
.setName("premlist")
.setCurrency(USD)
.setLabelsToPrices(TEST_PRICES)
.setCreationTime(fakeClock.nowUtc())
.build());
assertThat(PremiumListDao.getPremiumPrice("premlist", "silver")).hasValue(Money.of(USD, 10.23)); assertThat(PremiumListDao.getPremiumPrice("premlist", "silver")).hasValue(Money.of(USD, 10.23));
assertThat(PremiumListDao.getPremiumPrice("premlist", "gold")).hasValue(Money.of(USD, 1305.47)); assertThat(PremiumListDao.getPremiumPrice("premlist", "gold")).hasValue(Money.of(USD, 1305.47));
assertThat(PremiumListDao.getPremiumPrice("premlist", "zirconium")).isEmpty(); assertThat(PremiumListDao.getPremiumPrice("premlist", "zirconium")).isEmpty();
@ -226,29 +218,23 @@ public class PremiumListDaoTest {
@Test @Test
void testGetPremiumPrice_worksForJPY() { void testGetPremiumPrice_worksForJPY() {
PremiumList premiumList =
PremiumListDao.save(
new PremiumList.Builder()
.setName("premlist")
.setCurrency(JPY)
.setLabelsToPrices(
ImmutableMap.of(
"silver",
BigDecimal.valueOf(10.00),
"gold",
BigDecimal.valueOf(1000.0),
"palladium",
BigDecimal.valueOf(15000)))
.setCreationTime(fakeClock.nowUtc())
.build());
persistResource( persistResource(
newRegistry("foobar", "FOOBAR") newRegistry("foobar", "FOOBAR").asBuilder().setPremiumList(premiumList).build());
.asBuilder()
.setPremiumListKey(
Key.create(
getCrossTldKey(),
google.registry.model.registry.label.PremiumList.class,
"premlist"))
.build());
PremiumListDao.save(
new PremiumList.Builder()
.setName("premlist")
.setCurrency(JPY)
.setLabelsToPrices(
ImmutableMap.of(
"silver",
BigDecimal.valueOf(10.00),
"gold",
BigDecimal.valueOf(1000.0),
"palladium",
BigDecimal.valueOf(15000)))
.setCreationTime(fakeClock.nowUtc())
.build());
assertThat(PremiumListDao.getPremiumPrice("premlist", "silver")).hasValue(moneyOf(JPY, 10)); assertThat(PremiumListDao.getPremiumPrice("premlist", "silver")).hasValue(moneyOf(JPY, 10));
assertThat(PremiumListDao.getPremiumPrice("premlist", "gold")).hasValue(moneyOf(JPY, 1000)); assertThat(PremiumListDao.getPremiumPrice("premlist", "gold")).hasValue(moneyOf(JPY, 1000));
assertThat(PremiumListDao.getPremiumPrice("premlist", "palladium")) assertThat(PremiumListDao.getPremiumPrice("premlist", "palladium"))

View file

@ -32,7 +32,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Range; import com.google.common.collect.Range;
import com.googlecode.objectify.Key;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import java.math.BigDecimal; import java.math.BigDecimal;
import org.joda.money.Money; import org.joda.money.Money;
@ -279,7 +278,7 @@ class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
"--roid_suffix=Q9JYB4C", "--roid_suffix=Q9JYB4C",
"--dns_writers=VoidDnsWriter", "--dns_writers=VoidDnsWriter",
"xn--q9jyb4c"); "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getReservedLists().stream().map(Key::getName)) assertThat(Registry.get("xn--q9jyb4c").getReservedListNames())
.containsExactly("xn--q9jyb4c_abuse", "common_abuse"); .containsExactly("xn--q9jyb4c_abuse", "common_abuse");
} }
@ -519,9 +518,7 @@ class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
"--roid_suffix=Q9JYB4C", "--roid_suffix=Q9JYB4C",
"--dns_writers=FooDnsWriter", "--dns_writers=FooDnsWriter",
"xn--q9jyb4c"); "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getPremiumList()).isPresent(); assertThat(Registry.get("xn--q9jyb4c").getPremiumListName()).hasValue("xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getPremiumList().get().getName())
.isEqualTo("xn--q9jyb4c");
} }
@Test @Test

View file

@ -72,8 +72,7 @@ class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
assertThat(registry.getRoidSuffix()).isEqualTo(roidSuffix); assertThat(registry.getRoidSuffix()).isEqualTo(roidSuffix);
assertThat(registry.getTldState(DateTime.now(UTC))).isEqualTo(tldState); assertThat(registry.getTldState(DateTime.now(UTC))).isEqualTo(tldState);
assertThat(registry.getDnsWriters()).containsExactly("VoidDnsWriter"); assertThat(registry.getDnsWriters()).containsExactly("VoidDnsWriter");
assertThat(registry.getPremiumList()).isNotNull(); assertThat(registry.getPremiumListName()).hasValue("default_sandbox_list");
assertThat(registry.getPremiumList().get().getName()).isEqualTo("default_sandbox_list");
assertThat(registry.getAddGracePeriodLength()).isEqualTo(Duration.standardMinutes(60)); assertThat(registry.getAddGracePeriodLength()).isEqualTo(Duration.standardMinutes(60));
assertThat(registry.getRedemptionGracePeriodLength()).isEqualTo(Duration.standardMinutes(10)); assertThat(registry.getRedemptionGracePeriodLength()).isEqualTo(Duration.standardMinutes(10));
assertThat(registry.getPendingDeleteLength()).isEqualTo(Duration.standardMinutes(5)); assertThat(registry.getPendingDeleteLength()).isEqualTo(Duration.standardMinutes(5));

View file

@ -35,9 +35,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import com.beust.jcommander.ParameterException; import com.beust.jcommander.ParameterException;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import com.googlecode.objectify.Key;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.label.PremiumList;
import java.util.Optional; import java.util.Optional;
import org.joda.money.Money; import org.joda.money.Money;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@ -254,7 +252,7 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
void testSuccess_setReservedLists() throws Exception { void testSuccess_setReservedLists() throws Exception {
runCommandForced("--reserved_lists=xn--q9jyb4c_r1,xn--q9jyb4c_r2", "xn--q9jyb4c"); runCommandForced("--reserved_lists=xn--q9jyb4c_r1,xn--q9jyb4c_r2", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getReservedLists().stream().map(Key::getName)) assertThat(Registry.get("xn--q9jyb4c").getReservedListNames())
.containsExactly("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"); .containsExactly("xn--q9jyb4c_r1", "xn--q9jyb4c_r2");
} }
@ -264,7 +262,7 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"))
.build()); .build());
runCommandForced("--reserved_lists=xn--q9jyb4c_r2", "xn--q9jyb4c"); runCommandForced("--reserved_lists=xn--q9jyb4c_r2", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getReservedLists().stream().map(Key::getName)) assertThat(Registry.get("xn--q9jyb4c").getReservedListNames())
.containsExactly("xn--q9jyb4c_r2"); .containsExactly("xn--q9jyb4c_r2");
} }
@ -274,7 +272,7 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1")) .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1"))
.build()); .build());
runCommandForced("--add_reserved_lists=xn--q9jyb4c_r2", "xn--q9jyb4c"); runCommandForced("--add_reserved_lists=xn--q9jyb4c_r2", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getReservedLists().stream().map(Key::getName)) assertThat(Registry.get("xn--q9jyb4c").getReservedListNames())
.containsExactly("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"); .containsExactly("xn--q9jyb4c_r1", "xn--q9jyb4c_r2");
} }
@ -284,7 +282,7 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"))
.build()); .build());
runCommandForced("--remove_reserved_lists=xn--q9jyb4c_r1,xn--q9jyb4c_r2", "xn--q9jyb4c"); runCommandForced("--remove_reserved_lists=xn--q9jyb4c_r1,xn--q9jyb4c_r2", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getReservedLists()).isEmpty(); assertThat(Registry.get("xn--q9jyb4c").getReservedListNames()).isEmpty();
} }
@Test @Test
@ -293,7 +291,7 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
.setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2")) .setReservedListsByName(ImmutableSet.of("xn--q9jyb4c_r1", "xn--q9jyb4c_r2"))
.build()); .build());
runCommandForced("--remove_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c"); runCommandForced("--remove_reserved_lists=xn--q9jyb4c_r1", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getReservedLists().stream().map(Key::getName)) assertThat(Registry.get("xn--q9jyb4c").getReservedListNames())
.containsExactly("xn--q9jyb4c_r2"); .containsExactly("xn--q9jyb4c_r2");
} }
@ -839,21 +837,20 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
@Test @Test
void testSuccess_removePremiumListWithNull() throws Exception { void testSuccess_removePremiumListWithNull() throws Exception {
runCommandForced("--premium_list=null", "xn--q9jyb4c"); runCommandForced("--premium_list=null", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getPremiumList()).isEmpty(); assertThat(Registry.get("xn--q9jyb4c").getPremiumListName()).isEmpty();
} }
@Test @Test
void testSuccess_removePremiumListWithBlank() throws Exception { void testSuccess_removePremiumListWithBlank() throws Exception {
runCommandForced("--premium_list=", "xn--q9jyb4c"); runCommandForced("--premium_list=", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getPremiumList()).isEmpty(); assertThat(Registry.get("xn--q9jyb4c").getPremiumListName()).isEmpty();
} }
@Test @Test
void testSuccess_premiumListNotRemovedWhenNotSpecified() throws Exception { void testSuccess_premiumListNotRemovedWhenNotSpecified() throws Exception {
runCommandForced("--add_reserved_lists=xn--q9jyb4c_r1,xn--q9jyb4c_r2", "xn--q9jyb4c"); runCommandForced("--add_reserved_lists=xn--q9jyb4c_r1,xn--q9jyb4c_r2", "xn--q9jyb4c");
Optional<Key<PremiumList>> premiumListKey = Registry.get("xn--q9jyb4c").getPremiumList(); Optional<String> premiumListName = Registry.get("xn--q9jyb4c").getPremiumListName();
assertThat(premiumListKey).isPresent(); assertThat(premiumListName).hasValue("xn--q9jyb4c");
assertThat(premiumListKey.get().getName()).isEqualTo("xn--q9jyb4c");
} }
@Test @Test
@ -921,9 +918,7 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
@Test @Test
void testSuccess_setPremiumList() throws Exception { void testSuccess_setPremiumList() throws Exception {
runCommandForced("--premium_list=xn--q9jyb4c", "xn--q9jyb4c"); runCommandForced("--premium_list=xn--q9jyb4c", "xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getPremiumList()).isPresent(); assertThat(Registry.get("xn--q9jyb4c").getPremiumListName()).hasValue("xn--q9jyb4c");
assertThat(Registry.get("xn--q9jyb4c").getPremiumList().get().getName())
.isEqualTo("xn--q9jyb4c");
} }
@Test @Test

View file

@ -658,7 +658,6 @@ class google.registry.model.registry.Registry {
boolean dnsPaused; boolean dnsPaused;
boolean escrowEnabled; boolean escrowEnabled;
boolean invoicingEnabled; boolean invoicingEnabled;
com.googlecode.objectify.Key<google.registry.model.registry.label.PremiumList> premiumList;
google.registry.model.CreateAutoTimestamp creationTime; google.registry.model.CreateAutoTimestamp creationTime;
google.registry.model.common.TimedTransitionProperty<google.registry.model.registry.Registry$TldState, google.registry.model.registry.Registry$TldStateTransition> tldStateTransitions; google.registry.model.common.TimedTransitionProperty<google.registry.model.registry.Registry$TldState, google.registry.model.registry.Registry$TldStateTransition> tldStateTransitions;
google.registry.model.common.TimedTransitionProperty<org.joda.money.Money, google.registry.model.registry.Registry$BillingCostTransition> eapFeeSchedule; google.registry.model.common.TimedTransitionProperty<org.joda.money.Money, google.registry.model.registry.Registry$BillingCostTransition> eapFeeSchedule;
@ -672,7 +671,6 @@ class google.registry.model.registry.Registry {
java.lang.String roidSuffix; java.lang.String roidSuffix;
java.lang.String tldStr; java.lang.String tldStr;
java.lang.String tldUnicode; java.lang.String tldUnicode;
java.util.Set<com.googlecode.objectify.Key<google.registry.model.registry.label.ReservedList>> reservedLists;
java.util.Set<java.lang.String> allowedFullyQualifiedHostNames; java.util.Set<java.lang.String> allowedFullyQualifiedHostNames;
java.util.Set<java.lang.String> allowedRegistrantContactIds; java.util.Set<java.lang.String> allowedRegistrantContactIds;
java.util.Set<java.lang.String> dnsWriters; java.util.Set<java.lang.String> dnsWriters;