diff --git a/core/src/main/java/google/registry/tools/CreateReservedListCommand.java b/core/src/main/java/google/registry/tools/CreateReservedListCommand.java index 17078fb02..5921e30da 100644 --- a/core/src/main/java/google/registry/tools/CreateReservedListCommand.java +++ b/core/src/main/java/google/registry/tools/CreateReservedListCommand.java @@ -25,7 +25,9 @@ import com.beust.jcommander.Parameters; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Splitter; import com.google.common.base.Strings; +import com.googlecode.objectify.Key; import google.registry.model.registry.label.ReservedList; +import google.registry.persistence.VKey; import java.nio.file.Files; import java.util.List; import org.joda.time.DateTime; @@ -63,6 +65,12 @@ final class CreateReservedListCommand extends CreateOrUpdateReservedListCommand .setCreationTime(now) .setLastUpdateTime(now) .build(); + + // calls the stageEntityChange method that takes old entity, new entity and a new vkey; + // Because ReservedList is a sqlEntity and its primary key field (revisionId) is only set when + // it's being persisted; a vkey has to be created here explicitly for ReservedList instances. + stageEntityChange( + null, reservedList, VKey.createOfy(ReservedList.class, Key.create(reservedList))); } private static void validateListName(String name) { diff --git a/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java b/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java index 7d994fec1..52a38e473 100644 --- a/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java +++ b/core/src/test/java/google/registry/tools/CreateReservedListCommandTest.java @@ -23,8 +23,11 @@ import static google.registry.testing.DatabaseHelper.persistResource; import static google.registry.tools.CreateReservedListCommand.INVALID_FORMAT_ERROR_MESSAGE; import static org.junit.jupiter.api.Assertions.assertThrows; +import com.google.common.io.Files; import google.registry.model.registry.Registry; import google.registry.model.registry.label.ReservedList; +import java.nio.file.Path; +import java.nio.file.Paths; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -185,4 +188,26 @@ class CreateReservedListCommandTest runCommandForced("--name=" + name, "--override", "--input=" + reservedTermsPath); assertThat(ReservedList.get(name)).isPresent(); } + + @Test + void testStageEntityChange_succeeds() throws Exception { + CreateReservedListCommand command = new CreateReservedListCommand(); + // file content is populated in @BeforeEach of CreateOrUpdateReservedListCommandTestCase.java + command.input = Paths.get(reservedTermsPath); + command.init(); + assertThat(command.prompt()) + .contains( + "reservedListMap={baddies=baddies,FULLY_BLOCKED, " + + "ford=ford,FULLY_BLOCKED # random comment}"); + } + + @Test + void testStageEntityChange_succeedsWithEmptyFile() throws Exception { + Path tmpPath = tmpDir.resolve("xn--q9jyb4c_common-tmp.txt"); + Files.write(new byte[0], tmpPath.toFile()); + CreateReservedListCommand command = new CreateReservedListCommand(); + command.input = tmpPath; + command.init(); + assertThat(command.prompt()).contains("reservedListMap={}"); + } }