mirror of
https://github.com/google/nomulus.git
synced 2025-05-22 04:09:46 +02:00
Fix generics in EppXmlTransformer.unmarshal to not be only on the return type.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=124914271
This commit is contained in:
parent
6466ad51f6
commit
ec39f15a23
31 changed files with 133 additions and 62 deletions
|
@ -12,7 +12,6 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
package google.registry.flows;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
|
52
javatests/google/registry/flows/EppXmlTransformerTest.java
Normal file
52
javatests/google/registry/flows/EppXmlTransformerTest.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
// Copyright 2016 The Domain Registry Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
|
||||
package google.registry.flows;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
||||
import static google.registry.util.ResourceUtils.readResourceBytes;
|
||||
|
||||
import google.registry.model.eppinput.EppInput;
|
||||
import google.registry.model.eppoutput.EppOutput;
|
||||
import google.registry.testing.ExceptionRule;
|
||||
import google.registry.testing.ShardableTestCase;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Tests for {@link EppXmlTransformer}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class EppXmlTransformerTest extends ShardableTestCase {
|
||||
|
||||
@Rule
|
||||
public final ExceptionRule thrown = new ExceptionRule();
|
||||
|
||||
@Test
|
||||
public void testUnmarshalingEppInput() throws Exception {
|
||||
EppInput input = unmarshal(
|
||||
EppInput.class, readResourceBytes(getClass(), "testdata/contact_info.xml").read());
|
||||
assertThat(input.getCommandName()).isEqualTo("Info");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalingWrongClassThrows() throws Exception {
|
||||
thrown.expect(ClassCastException.class);
|
||||
EppXmlTransformer.unmarshal(
|
||||
EppOutput.class, readResourceBytes(getClass(), "testdata/contact_info.xml").read());
|
||||
}
|
||||
}
|
|
@ -1140,6 +1140,7 @@ public class DomainApplicationCreateFlowTest
|
|||
.setCreateBillingCost(Money.of(EUR, 13))
|
||||
.setRestoreBillingCost(Money.of(EUR, 11))
|
||||
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
|
||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
||||
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
|
||||
.build());
|
||||
persistContactsAndHosts();
|
||||
|
|
|
@ -560,6 +560,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
|||
.setCreateBillingCost(Money.of(EUR, 13))
|
||||
.setRestoreBillingCost(Money.of(EUR, 11))
|
||||
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
|
||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
||||
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
|
||||
.build());
|
||||
persistContactsAndHosts();
|
||||
|
|
|
@ -341,6 +341,7 @@ public class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, D
|
|||
.setCreateBillingCost(Money.of(EUR, 13))
|
||||
.setRestoreBillingCost(Money.of(EUR, 11))
|
||||
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
|
||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
||||
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
|
||||
.build());
|
||||
persistDomain();
|
||||
|
|
|
@ -285,6 +285,7 @@ public class DomainRestoreRequestFlowTest extends
|
|||
.setCreateBillingCost(Money.of(EUR, 13))
|
||||
.setRestoreBillingCost(Money.of(EUR, 11))
|
||||
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
|
||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
||||
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
|
||||
.build());
|
||||
runFlow();
|
||||
|
|
|
@ -444,6 +444,7 @@ public class DomainTransferRequestFlowTest
|
|||
.setCreateBillingCost(Money.of(EUR, 13))
|
||||
.setRestoreBillingCost(Money.of(EUR, 11))
|
||||
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(EUR, 7)))
|
||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
||||
.setServerStatusChangeBillingCost(Money.of(EUR, 19))
|
||||
.build());
|
||||
doFailingTest("domain_transfer_request_fee.xml");
|
||||
|
|
|
@ -67,6 +67,7 @@ public final class RegistrarBillingUtilsTest {
|
|||
.setCurrency(JPY)
|
||||
.setRenewBillingCostTransitions(
|
||||
ImmutableSortedMap.of(START_OF_TIME, Money.parse("JPY 110")))
|
||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.parse("JPY 0")))
|
||||
.setCreateBillingCost(Money.parse("JPY 130"))
|
||||
.setRestoreBillingCost(Money.parse("JPY 170"))
|
||||
.setServerStatusChangeBillingCost(Money.parse("JPY 190"))
|
||||
|
|
|
@ -197,7 +197,7 @@ public class RdeReportActionTest {
|
|||
|
||||
private static XjcRdeReportReport parseReport(byte[] data) {
|
||||
try {
|
||||
return XjcXmlTransformer.unmarshal(new ByteArrayInputStream(data));
|
||||
return XjcXmlTransformer.unmarshal(XjcRdeReportReport.class, new ByteArrayInputStream(data));
|
||||
} catch (XmlException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
|
@ -200,8 +200,9 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
|||
action.run();
|
||||
executeTasksUntilEmpty("mapreduce", clock);
|
||||
|
||||
XjcRdeDeposit deposit =
|
||||
unmarshal(Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey).getData());
|
||||
XjcRdeDeposit deposit = unmarshal(
|
||||
XjcRdeDeposit.class,
|
||||
Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey).getData());
|
||||
XjcRdeHeader header = extractAndRemoveContentWithType(XjcRdeHeader.class, deposit);
|
||||
|
||||
assertThat(header.getTld()).isEqualTo("lol");
|
||||
|
@ -230,8 +231,9 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
|||
action.run();
|
||||
executeTasksUntilEmpty("mapreduce", clock);
|
||||
|
||||
XjcRdeDeposit deposit =
|
||||
unmarshal(Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey).getData());
|
||||
XjcRdeDeposit deposit = unmarshal(
|
||||
XjcRdeDeposit.class,
|
||||
Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey).getData());
|
||||
assertThat(deposit.getType()).isEqualTo(XjcRdeDepositTypeType.FULL);
|
||||
assertThat(deposit.getId()).isEqualTo(RdeUtil.timestampToId(DateTime.parse("2000-01-01TZ")));
|
||||
assertThat(deposit.getWatermark()).isEqualTo(DateTime.parse("2000-01-01TZ"));
|
||||
|
@ -271,8 +273,9 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
|||
action.run();
|
||||
executeTasksUntilEmpty("mapreduce", clock);
|
||||
|
||||
XjcRdeDeposit deposit =
|
||||
unmarshal(Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey).getData());
|
||||
XjcRdeDeposit deposit = unmarshal(
|
||||
XjcRdeDeposit.class,
|
||||
Ghostryde.decode(readGcsFile(gcsService, XML_FILE), decryptKey).getData());
|
||||
XjcRdeRegistrar registrar1 = extractAndRemoveContentWithType(XjcRdeRegistrar.class, deposit);
|
||||
XjcRdeRegistrar registrar2 = extractAndRemoveContentWithType(XjcRdeRegistrar.class, deposit);
|
||||
XjcRdeHeader header = extractAndRemoveContentWithType(XjcRdeHeader.class, deposit);
|
||||
|
@ -349,8 +352,9 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
|||
for (GcsFilename filename : asList(
|
||||
new GcsFilename("rde-bucket", "fop_1971-01-01_full_S1_R0.xml.ghostryde"),
|
||||
new GcsFilename("rde-bucket", "fop_1971-01-05_thin_S1_R0.xml.ghostryde"))) {
|
||||
XjcRdeDeposit deposit =
|
||||
unmarshal(Ghostryde.decode(readGcsFile(gcsService, filename), decryptKey).getData());
|
||||
XjcRdeDeposit deposit = unmarshal(
|
||||
XjcRdeDeposit.class,
|
||||
Ghostryde.decode(readGcsFile(gcsService, filename), decryptKey).getData());
|
||||
XjcRdeRegistrar registrar1 = extractAndRemoveContentWithType(XjcRdeRegistrar.class, deposit);
|
||||
XjcRdeRegistrar registrar2 = extractAndRemoveContentWithType(XjcRdeRegistrar.class, deposit);
|
||||
XjcRdeHeader header = extractAndRemoveContentWithType(XjcRdeHeader.class, deposit);
|
||||
|
@ -377,8 +381,9 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
|||
executeTasksUntilEmpty("mapreduce", clock);
|
||||
|
||||
GcsFilename filename = new GcsFilename("rde-bucket", "fop_2000-01-01_full_S1_R0.xml.ghostryde");
|
||||
XjcRdeDeposit deposit =
|
||||
unmarshal(Ghostryde.decode(readGcsFile(gcsService, filename), decryptKey).getData());
|
||||
XjcRdeDeposit deposit = unmarshal(
|
||||
XjcRdeDeposit.class,
|
||||
Ghostryde.decode(readGcsFile(gcsService, filename), decryptKey).getData());
|
||||
XjcRdeDomain domain = extractAndRemoveContentWithType(XjcRdeDomain.class, deposit);
|
||||
XjcRdeIdn firstIdn = extractAndRemoveContentWithType(XjcRdeIdn.class, deposit);
|
||||
XjcRdeHeader header = extractAndRemoveContentWithType(XjcRdeHeader.class, deposit);
|
||||
|
@ -494,16 +499,17 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
|||
action.run();
|
||||
executeTasksUntilEmpty("mapreduce", clock);
|
||||
|
||||
XjcRdeDeposit deposit =
|
||||
unmarshal(readXml("fop_2000-01-01_full_S1_R0.xml.ghostryde").getBytes(UTF_8));
|
||||
XjcRdeDeposit deposit = unmarshal(
|
||||
XjcRdeDeposit.class,
|
||||
readXml("fop_2000-01-01_full_S1_R0.xml.ghostryde").getBytes(UTF_8));
|
||||
assertThat(deposit.getResend()).isEqualTo(0);
|
||||
|
||||
setCursor(Registry.get("fop"), RDE_STAGING, DateTime.parse("2000-01-01TZ"));
|
||||
action.response = new FakeResponse();
|
||||
action.run();
|
||||
executeTasksUntilEmpty("mapreduce", clock);
|
||||
|
||||
deposit = unmarshal(readXml("fop_2000-01-01_full_S1_R1.xml.ghostryde").getBytes(UTF_8));
|
||||
deposit = unmarshal(
|
||||
XjcRdeDeposit.class, readXml("fop_2000-01-01_full_S1_R1.xml.ghostryde").getBytes(UTF_8));
|
||||
assertThat(deposit.getResend()).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
@ -621,7 +627,7 @@ public class RdeStagingActionTest extends MapreduceTestCase<RdeStagingAction> {
|
|||
}});
|
||||
}
|
||||
|
||||
public static <T> T unmarshal(byte[] xml) throws XmlException {
|
||||
return XjcXmlTransformer.unmarshal(new ByteArrayInputStream(xml));
|
||||
public static <T> T unmarshal(Class<T> clazz, byte[] xml) throws XmlException {
|
||||
return XjcXmlTransformer.unmarshal(clazz, new ByteArrayInputStream(xml));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -230,6 +230,7 @@ public class DatastoreHelper {
|
|||
.setTldStateTransitions(tldStates)
|
||||
// Set billing costs to distinct small primes to avoid masking bugs in tests.
|
||||
.setRenewBillingCostTransitions(ImmutableSortedMap.of(START_OF_TIME, Money.of(USD, 11)))
|
||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(USD)))
|
||||
.setCreateBillingCost(Money.of(USD, 13))
|
||||
.setRestoreBillingCost(Money.of(USD, 17))
|
||||
.setServerStatusChangeBillingCost(Money.of(USD, 19))
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
|
||||
package google.registry.testing;
|
||||
|
||||
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
||||
import static google.registry.testing.TestDataHelper.loadFileWithSubstitutions;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import google.registry.flows.EppXmlTransformer;
|
||||
import google.registry.model.eppinput.EppInput;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -38,7 +38,7 @@ public class EppLoader {
|
|||
}
|
||||
|
||||
public EppInput getEpp() throws Exception {
|
||||
return EppXmlTransformer.unmarshal(eppXml.getBytes(UTF_8));
|
||||
return unmarshal(EppInput.class, eppXml.getBytes(UTF_8));
|
||||
}
|
||||
|
||||
public String getEppXml() {
|
||||
|
|
|
@ -18,6 +18,7 @@ import static com.google.common.io.BaseEncoding.base16;
|
|||
import static com.google.common.io.Resources.getResource;
|
||||
import static com.google.common.io.Resources.toByteArray;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.flows.EppXmlTransformer.unmarshal;
|
||||
import static google.registry.flows.picker.FlowPicker.getFlowClass;
|
||||
import static google.registry.model.domain.DesignatedContact.Type.ADMIN;
|
||||
import static google.registry.model.domain.DesignatedContact.Type.BILLING;
|
||||
|
@ -37,7 +38,6 @@ import com.google.common.collect.ImmutableSet;
|
|||
import com.beust.jcommander.ParameterException;
|
||||
import com.googlecode.objectify.Ref;
|
||||
|
||||
import google.registry.flows.EppXmlTransformer;
|
||||
import google.registry.flows.domain.DomainAllocateFlow;
|
||||
import google.registry.model.domain.DesignatedContact;
|
||||
import google.registry.model.domain.DomainApplication;
|
||||
|
@ -157,9 +157,8 @@ public class AllocateDomainCommandTest extends CommandTestCase<AllocateDomainCom
|
|||
|
||||
@Test
|
||||
public void testXmlInstantiatesFlow() throws Exception {
|
||||
assertThat(
|
||||
getFlowClass(EppXmlTransformer.<EppInput>unmarshal(
|
||||
readResourceBytes(getClass(), "testdata/allocate_domain.xml").read())))
|
||||
.isEqualTo(DomainAllocateFlow.class);
|
||||
byte[] xmlBytes = readResourceBytes(getClass(), "testdata/allocate_domain.xml").read();
|
||||
assertThat(getFlowClass(unmarshal(EppInput.class, xmlBytes)))
|
||||
.isEqualTo(DomainAllocateFlow.class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ public class GenerateEscrowDepositCommandTest
|
|||
}
|
||||
|
||||
public static Object unmarshal(byte[] xml) throws XmlException {
|
||||
return XjcXmlTransformer.unmarshal(new ByteArrayInputStream(xml));
|
||||
return XjcXmlTransformer.unmarshal(Object.class, new ByteArrayInputStream(xml));
|
||||
}
|
||||
|
||||
private static ImmutableMap<String, Long> mapifyCounts(XjcRdeHeader header) {
|
||||
|
|
|
@ -199,6 +199,7 @@ public class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
|
|||
.setRestoreBillingCost(Money.ofMajor(JPY, 1))
|
||||
.setRenewBillingCostTransitions(
|
||||
ImmutableSortedMap.of(START_OF_TIME, Money.ofMajor(JPY, 1)))
|
||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(JPY)))
|
||||
.setServerStatusChangeBillingCost(Money.ofMajor(JPY, 1))
|
||||
.build());
|
||||
runCommandForced(
|
||||
|
|
|
@ -86,7 +86,7 @@ public class XjcObjectTest {
|
|||
|
||||
@Test
|
||||
public void testUnmarshalUTF16() throws Exception {
|
||||
XjcRdeDeposit deposit = unmarshal(new ByteArrayInputStream(
|
||||
XjcRdeDeposit deposit = unmarshal(XjcRdeDeposit.class, new ByteArrayInputStream(
|
||||
RDE_DEPOSIT_FULL.replaceFirst("UTF-8", "UTF-16").getBytes(UTF_16)));
|
||||
assertThat(deposit).isNotNull();
|
||||
assertThat(deposit.getType()).isEqualTo(XjcRdeDepositTypeType.FULL);
|
||||
|
@ -96,7 +96,7 @@ public class XjcObjectTest {
|
|||
@Test
|
||||
public void testUnmarshalValidation() throws Exception {
|
||||
thrown.expect(Throwable.class, "pattern '\\w{1,13}' for type 'depositIdType'");
|
||||
unmarshal(new ByteArrayInputStream(
|
||||
unmarshal(XjcRdeDeposit.class, new ByteArrayInputStream(
|
||||
RDE_DEPOSIT_FULL.replaceFirst("id=\"[^\"]+\"", "id=\"\"").getBytes(UTF_8)));
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@ public class XjcObjectTest {
|
|||
|
||||
@Test
|
||||
public void testNamespaceEpp() throws Exception {
|
||||
String xml = unmarshal(new ByteArrayInputStream(readResourceUtf8(
|
||||
String xml = unmarshal(XjcObject.class, new ByteArrayInputStream(readResourceUtf8(
|
||||
XjcObjectTest.class, "testdata/greeting.xml").getBytes(UTF_8))).toString();
|
||||
assertWithMessage(xml).that(xml).startsWith("<epp:epp ");
|
||||
assertWithMessage(xml).that(xml).contains("\"urn:ietf:params:xml:ns:epp-1.0\"");
|
||||
|
@ -124,6 +124,7 @@ public class XjcObjectTest {
|
|||
|
||||
/** Unmarshals XML assuming UTF-8 encoding. */
|
||||
private static XjcRdeDeposit unmarshalFullDeposit() throws Exception {
|
||||
return unmarshal(new ByteArrayInputStream(RDE_DEPOSIT_FULL.getBytes(UTF_8)));
|
||||
return unmarshal(
|
||||
XjcRdeDeposit.class, new ByteArrayInputStream(RDE_DEPOSIT_FULL.getBytes(UTF_8)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,13 +147,13 @@ public class XmlTestdataTest {
|
|||
|
||||
@Theory
|
||||
public void testValid(Good v) throws Exception {
|
||||
XjcObject xml = unmarshal(v.xmlStream);
|
||||
XjcObject xml = unmarshal(XjcObject.class, v.xmlStream);
|
||||
assertThat(xml).isInstanceOf(v.clazz);
|
||||
}
|
||||
|
||||
@Theory
|
||||
public void testInvalid(Evil v) throws Exception {
|
||||
thrown.expectMessage(v.error);
|
||||
unmarshal(v.xmlStream);
|
||||
unmarshal(XjcObject.class, v.xmlStream);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue