mirror of
https://github.com/google/nomulus.git
synced 2025-07-22 02:36:03 +02:00
Add a check so newly saved createCostTransitions get recognized and saved to the database (#2335)
* Add a check so newly saved createCostTransitions get recognized and saved to the database * Fix equals check * Rename equals method * Add comment explaining need for createBillingCostTransitionEqualCheck
This commit is contained in:
parent
a4bd85068b
commit
02fd6d4756
2 changed files with 37 additions and 1 deletions
|
@ -138,7 +138,10 @@ public class Tld extends ImmutableObject implements Buildable, UnsafeSerializabl
|
|||
try {
|
||||
String thisYaml = mapper.writeValueAsString(this);
|
||||
String otherYaml = mapper.writeValueAsString(tldToCompare);
|
||||
return thisYaml.equals(otherYaml);
|
||||
// Since Jackson uses getters and not field values to construct the YAML representation, an
|
||||
// explicit check of the createBillingCostTransitions is necessary since this field is
|
||||
// auto-populated in the getter when the field is set to null.
|
||||
return thisYaml.equals(otherYaml) && createBillingCostTransitionsEqual(tldToCompare);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -692,6 +695,15 @@ public class Tld extends ImmutableObject implements Buildable, UnsafeSerializabl
|
|||
.toValueMap();
|
||||
}
|
||||
|
||||
public boolean createBillingCostTransitionsEqual(Tld newTld) {
|
||||
if (createBillingCostTransitions == null) {
|
||||
return false;
|
||||
}
|
||||
return createBillingCostTransitions
|
||||
.toValueMap()
|
||||
.equals(newTld.getCreateBillingCostTransitions());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the add-on cost of a domain restore (the flat tld-wide fee charged in addition to one
|
||||
* year of renewal for that name).
|
||||
|
|
|
@ -140,6 +140,8 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
|
|||
tld.asBuilder()
|
||||
.setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN))
|
||||
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta"))
|
||||
.setCreateBillingCostTransitions(
|
||||
ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 13)))
|
||||
.build());
|
||||
File tldFile = tmpDir.resolve("idns.yaml").toFile();
|
||||
Files.asCharSink(tldFile, UTF_8).write(loadFile(getClass(), "idns.yaml"));
|
||||
|
@ -149,6 +151,22 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
|
|||
.hasLogAtLevelWithMessage(INFO, "TLD YAML file contains no new changes");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_addCreateCostTransitions_hasDiff() throws Exception {
|
||||
Tld tld = createTld("idns");
|
||||
persistResource(
|
||||
tld.asBuilder()
|
||||
.setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN))
|
||||
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta"))
|
||||
.build());
|
||||
File tldFile = tmpDir.resolve("idns.yaml").toFile();
|
||||
Files.asCharSink(tldFile, UTF_8).write(loadFile(getClass(), "idns.yaml"));
|
||||
runCommandForced("--input=" + tldFile);
|
||||
Tld updatedTld = Tld.get("idns");
|
||||
testTldConfiguredSuccessfully(updatedTld, "idns.yaml");
|
||||
assertThat(tld.createBillingCostTransitionsEqual(updatedTld)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_outOfOrderFieldsOnCreate() throws Exception {
|
||||
File tldFile = tmpDir.resolve("outoforderfields.yaml").toFile();
|
||||
|
@ -580,6 +598,8 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
|
|||
tld.asBuilder()
|
||||
.setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN))
|
||||
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta"))
|
||||
.setCreateBillingCostTransitions(
|
||||
ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 13)))
|
||||
.build());
|
||||
File tldFile = tmpDir.resolve("idns.yaml").toFile();
|
||||
Files.asCharSink(tldFile, UTF_8).write(loadFile(getClass(), "idns.yaml"));
|
||||
|
@ -626,6 +646,8 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
|
|||
tld.asBuilder()
|
||||
.setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN))
|
||||
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta"))
|
||||
.setCreateBillingCostTransitions(
|
||||
ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 13)))
|
||||
.setBreakglassMode(true)
|
||||
.build());
|
||||
File tldFile = tmpDir.resolve("idns.yaml").toFile();
|
||||
|
@ -645,6 +667,8 @@ public class ConfigureTldCommandTest extends CommandTestCase<ConfigureTldCommand
|
|||
tld.asBuilder()
|
||||
.setIdnTables(ImmutableSet.of(JA, UNCONFUSABLE_LATIN, EXTENDED_LATIN))
|
||||
.setAllowedFullyQualifiedHostNames(ImmutableSet.of("zeta", "alpha", "gamma", "beta"))
|
||||
.setCreateBillingCostTransitions(
|
||||
ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 13)))
|
||||
.setBreakglassMode(true)
|
||||
.build());
|
||||
File tldFile = tmpDir.resolve("idns.yaml").toFile();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue