diff --git a/javatests/google/registry/flows/domain/DomainRenewFlowTest.java b/javatests/google/registry/flows/domain/DomainRenewFlowTest.java index 4b56cf06e..92775b1f7 100644 --- a/javatests/google/registry/flows/domain/DomainRenewFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainRenewFlowTest.java @@ -29,6 +29,7 @@ import static google.registry.testing.DomainBaseSubject.assertAboutDomains; import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions; import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries; import static google.registry.testing.JUnitBackports.assertThrows; +import static google.registry.testing.TestDataHelper.updateSubstitutions; import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.START_OF_TIME; import static org.joda.money.CurrencyUnit.EUR; @@ -78,12 +79,20 @@ import org.junit.Test; /** Unit tests for {@link DomainRenewFlow}. */ public class DomainRenewFlowTest extends ResourceFlowTestCase { + private static final ImmutableMap FEE_BASE_MAP = + ImmutableMap.of( + "NAME", "example.tld", + "PERIOD", "5", + "EX_DATE", "2005-04-03T22:00:00.0Z", + "FEE", "55.00", + "CURRENCY", "USD"); + private static final ImmutableMap FEE_06_MAP = - ImmutableMap.of("FEE_VERSION", "0.6", "FEE_NS", "fee", "CURRENCY", "USD"); + updateSubstitutions(FEE_BASE_MAP, "FEE_VERSION", "0.6", "FEE_NS", "fee"); private static final ImmutableMap FEE_11_MAP = - ImmutableMap.of("FEE_VERSION", "0.11", "FEE_NS", "fee11", "CURRENCY", "USD"); + updateSubstitutions(FEE_BASE_MAP, "FEE_VERSION", "0.11", "FEE_NS", "fee11"); private static final ImmutableMap FEE_12_MAP = - ImmutableMap.of("FEE_VERSION", "0.12", "FEE_NS", "fee12", "CURRENCY", "USD"); + updateSubstitutions(FEE_BASE_MAP, "FEE_VERSION", "0.12", "FEE_NS", "fee12"); final DateTime expirationTime = DateTime.parse("2000-04-03T22:00:00.0Z"); @@ -251,21 +260,16 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase() - .put("DOMAIN", "costly-renew.tld") - .put("FEE_VERSION", "0.6") - .put("FEE_NS", "fee") - .put("AMOUNT", "111.00") - .put("EX_DATE", "2001-04-03T22:00:00.000Z") - .build(), - Money.of(USD, 111)); + doSuccessfulTest("domain_renew_response_fee.xml", 1, customFeeMap, Money.of(USD, 111)); } @Test @@ -312,9 +316,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase parameters = - ImmutableMap.of("FEE_VERSION", "0.6", "FEE_NS", "fee", "CURRENCY", "BAD"); - setEppInput("domain_renew_fee.xml", parameters); + setEppInput("domain_renew_fee.xml", updateSubstitutions(FEE_06_MAP, "CURRENCY", "BAD")); EppException thrown = assertThrows(UnknownCurrencyEppException.class, this::persistDomain); assertAboutEppExceptions().that(thrown).marshalsToXml(); } diff --git a/javatests/google/registry/flows/domain/testdata/domain_renew_fee.xml b/javatests/google/registry/flows/domain/testdata/domain_renew_fee.xml index 2e06318e0..f019a8e03 100644 --- a/javatests/google/registry/flows/domain/testdata/domain_renew_fee.xml +++ b/javatests/google/registry/flows/domain/testdata/domain_renew_fee.xml @@ -3,15 +3,15 @@ - example.tld + %NAME% 2000-04-03 - 5 + %PERIOD% %CURRENCY% - 55.00 + %FEE% ABC-12345 diff --git a/javatests/google/registry/flows/domain/testdata/domain_renew_fee_wildcard.xml b/javatests/google/registry/flows/domain/testdata/domain_renew_fee_wildcard.xml deleted file mode 100644 index 8fa516c9f..000000000 --- a/javatests/google/registry/flows/domain/testdata/domain_renew_fee_wildcard.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - %DOMAIN% - 2000-04-03 - 1 - - - - - USD - %AMOUNT% - - - ABC-12345 - - diff --git a/javatests/google/registry/flows/domain/testdata/domain_renew_response_fee.xml b/javatests/google/registry/flows/domain/testdata/domain_renew_response_fee.xml index ae09605ab..6c28a2fde 100644 --- a/javatests/google/registry/flows/domain/testdata/domain_renew_response_fee.xml +++ b/javatests/google/registry/flows/domain/testdata/domain_renew_response_fee.xml @@ -6,14 +6,14 @@ - example.tld - 2005-04-03T22:00:00.0Z + %NAME% + %EX_DATE% <%FEE_NS%:renData xmlns:%FEE_NS%="urn:ietf:params:xml:ns:fee-%FEE_VERSION%"> - <%FEE_NS%:currency>USD - <%FEE_NS%:fee description="renew">55.00 + <%FEE_NS%:currency>%CURRENCY% + <%FEE_NS%:fee description="renew">%FEE% diff --git a/javatests/google/registry/flows/domain/testdata/domain_renew_response_fee_wildcard.xml b/javatests/google/registry/flows/domain/testdata/domain_renew_response_fee_wildcard.xml deleted file mode 100644 index 20175216c..000000000 --- a/javatests/google/registry/flows/domain/testdata/domain_renew_response_fee_wildcard.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - Command completed successfully - - - - %DOMAIN% - %EX_DATE% - - - - <%FEE_NS%:renData xmlns:%FEE_NS%="urn:ietf:params:xml:ns:fee-%FEE_VERSION%"> - <%FEE_NS%:currency>USD - <%FEE_NS%:fee description="renew">%AMOUNT% - - - - ABC-12345 - server-trid - - - diff --git a/javatests/google/registry/testing/TestDataHelper.java b/javatests/google/registry/testing/TestDataHelper.java index 49dcd83c7..2e2c354c6 100644 --- a/javatests/google/registry/testing/TestDataHelper.java +++ b/javatests/google/registry/testing/TestDataHelper.java @@ -14,6 +14,9 @@ package google.registry.testing; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.Maps.newHashMap; import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.ResourceUtils.readResourceBytes; import static google.registry.util.ResourceUtils.readResourceUtf8; @@ -51,6 +54,24 @@ public final class TestDataHelper { private static final Map fileCache = new ConcurrentHashMap<>(); private static final Map byteCache = new ConcurrentHashMap<>(); + /** + * Returns a copy of the given substitution map, updated with the new keys and values. + * + *

If an existing key is given, its value will be overridden with the new value. + */ + public static ImmutableMap updateSubstitutions( + @Nullable Map baseSubstitutions, String... keysAndValues) { + checkArgument( + keysAndValues.length % 2 == 0, + "keysAndValues must have even number of parameters, but has %s", + keysAndValues.length); + Map newSubstitutions = newHashMap(nullToEmpty(baseSubstitutions)); + for (int i = 0; i < keysAndValues.length; i += 2) { + newSubstitutions.put(checkNotNull(keysAndValues[i]), checkNotNull(keysAndValues[i + 1])); + } + return ImmutableMap.copyOf(newSubstitutions); + } + /** * Loads a text file from the "testdata" directory relative to the location of the specified * context class.