Consolidate the domain_renew_fee xml test files

Moving some of the info into the java test file itself makes it more easily readable. Maybe.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=240148747
This commit is contained in:
guyben 2019-03-25 08:57:48 -07:00 committed by jianglai
parent c25486ec32
commit 625181ee3d
6 changed files with 50 additions and 70 deletions

View file

@ -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<DomainRenewFlow, DomainBase> {
private static final ImmutableMap<String, String> 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<String, String> 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<String, String> 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<String, String> 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<DomainRenewFlow, D
public void testSuccess_customLogicFee() throws Exception {
// The "costly-renew" domain has an additional RENEW fee of 100 from custom logic on top of the
// normal $11 standard renew price for this TLD.
setEppInput(
"domain_renew_fee_wildcard.xml",
ImmutableMap.of("DOMAIN", "costly-renew.tld", "FEE_VERSION", "0.6", "AMOUNT", "111.00"));
ImmutableMap customFeeMap =
updateSubstitutions(
FEE_06_MAP,
"NAME", "costly-renew.tld",
"PERIOD", "1",
"EX_DATE", "2001-04-03T22:00:00.0Z",
"FEE", "111.00");
setEppInput("domain_renew_fee.xml", customFeeMap);
persistDomain();
doSuccessfulTest(
"domain_renew_response_fee_wildcard.xml",
1,
new ImmutableMap.Builder<String, String>()
.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<DomainRenewFlow, D
@Test
public void testFailure_fee_unknownCurrency() {
ImmutableMap<String, String> 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();
}

View file

@ -3,15 +3,15 @@
<renew>
<domain:renew
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:name>%NAME%</domain:name>
<domain:curExpDate>2000-04-03</domain:curExpDate>
<domain:period unit="y">5</domain:period>
<domain:period unit="y">%PERIOD%</domain:period>
</domain:renew>
</renew>
<extension>
<fee:renew xmlns:fee="urn:ietf:params:xml:ns:fee-%FEE_VERSION%">
<fee:currency>%CURRENCY%</fee:currency>
<fee:fee>55.00</fee:fee>
<fee:fee>%FEE%</fee:fee>
</fee:renew>
</extension>
<clTRID>ABC-12345</clTRID>

View file

@ -1,19 +0,0 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<renew>
<domain:renew
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>%DOMAIN%</domain:name>
<domain:curExpDate>2000-04-03</domain:curExpDate>
<domain:period unit="y">1</domain:period>
</domain:renew>
</renew>
<extension>
<fee:renew xmlns:fee="urn:ietf:params:xml:ns:fee-%FEE_VERSION%">
<fee:currency>USD</fee:currency>
<fee:fee>%AMOUNT%</fee:fee>
</fee:renew>
</extension>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -6,14 +6,14 @@
<resData>
<domain:renData
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:exDate>2005-04-03T22:00:00.0Z</domain:exDate>
<domain:name>%NAME%</domain:name>
<domain:exDate>%EX_DATE%</domain:exDate>
</domain:renData>
</resData>
<extension>
<%FEE_NS%:renData xmlns:%FEE_NS%="urn:ietf:params:xml:ns:fee-%FEE_VERSION%">
<%FEE_NS%:currency>USD</%FEE_NS%:currency>
<%FEE_NS%:fee description="renew">55.00</%FEE_NS%:fee>
<%FEE_NS%:currency>%CURRENCY%</%FEE_NS%:currency>
<%FEE_NS%:fee description="renew">%FEE%</%FEE_NS%:fee>
</%FEE_NS%:renData>
</extension>
<trID>

View file

@ -1,24 +0,0 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<domain:renData
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>%DOMAIN%</domain:name>
<domain:exDate>%EX_DATE%</domain:exDate>
</domain:renData>
</resData>
<extension>
<%FEE_NS%:renData xmlns:%FEE_NS%="urn:ietf:params:xml:ns:fee-%FEE_VERSION%">
<%FEE_NS%:currency>USD</%FEE_NS%:currency>
<%FEE_NS%:fee description="renew">%AMOUNT%</%FEE_NS%:fee>
</%FEE_NS%:renData>
</extension>
<trID>
<clTRID>ABC-12345</clTRID>
<svTRID>server-trid</svTRID>
</trID>
</response>
</epp>

View file

@ -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<FileKey, String> fileCache = new ConcurrentHashMap<>();
private static final Map<FileKey, ByteSource> byteCache = new ConcurrentHashMap<>();
/**
* Returns a copy of the given substitution map, updated with the new keys and values.
*
* <p>If an existing key is given, its value will be overridden with the new value.
*/
public static ImmutableMap<String, String> updateSubstitutions(
@Nullable Map<String, String> baseSubstitutions, String... keysAndValues) {
checkArgument(
keysAndValues.length % 2 == 0,
"keysAndValues must have even number of parameters, but has %s",
keysAndValues.length);
Map<String, String> 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.