mirror of
https://github.com/google/nomulus.git
synced 2025-08-15 14:04:06 +02:00
Add stageEntityChange() method to display difference when creating a reserved list (#1149)
* Add stageEntityChange() method to display difference before execution when creating a reserved list
This commit is contained in:
parent
484e30cd80
commit
85bac9834f
2 changed files with 33 additions and 0 deletions
|
@ -25,7 +25,9 @@ import com.beust.jcommander.Parameters;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
import com.googlecode.objectify.Key;
|
||||||
import google.registry.model.registry.label.ReservedList;
|
import google.registry.model.registry.label.ReservedList;
|
||||||
|
import google.registry.persistence.VKey;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
@ -63,6 +65,12 @@ final class CreateReservedListCommand extends CreateOrUpdateReservedListCommand
|
||||||
.setCreationTime(now)
|
.setCreationTime(now)
|
||||||
.setLastUpdateTime(now)
|
.setLastUpdateTime(now)
|
||||||
.build();
|
.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) {
|
private static void validateListName(String name) {
|
||||||
|
|
|
@ -23,8 +23,11 @@ import static google.registry.testing.DatabaseHelper.persistResource;
|
||||||
import static google.registry.tools.CreateReservedListCommand.INVALID_FORMAT_ERROR_MESSAGE;
|
import static google.registry.tools.CreateReservedListCommand.INVALID_FORMAT_ERROR_MESSAGE;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
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.Registry;
|
||||||
import google.registry.model.registry.label.ReservedList;
|
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.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@ -185,4 +188,26 @@ class CreateReservedListCommandTest
|
||||||
runCommandForced("--name=" + name, "--override", "--input=" + reservedTermsPath);
|
runCommandForced("--name=" + name, "--override", "--input=" + reservedTermsPath);
|
||||||
assertThat(ReservedList.get(name)).isPresent();
|
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={}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue