Refactor EppXmlTransformer to be in the model/ package

This will allow us to perform the OT&E history verification
in the model/ package as well so that it can be used both
by both the UI and the command line tool.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=225007167
This commit is contained in:
jianglai 2018-12-11 08:25:20 -08:00
parent f58211402a
commit 0a44ef0dca
27 changed files with 257 additions and 240 deletions

View file

@ -16,7 +16,7 @@ package google.registry.flows;
import static com.google.common.io.BaseEncoding.base64;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.EppXmlTransformer.marshal;
import static google.registry.model.eppcommon.EppXmlTransformer.marshal;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.LogsSubject.assertAboutLogs;
import static google.registry.testing.TestDataHelper.loadFile;

View file

@ -35,6 +35,7 @@ import google.registry.model.billing.BillingEvent.Flag;
import google.registry.model.billing.BillingEvent.OneTime;
import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainResource;
import google.registry.model.eppcommon.EppXmlTransformer;
import google.registry.model.ofy.Ofy;
import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry;

View file

@ -19,7 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.Sets.difference;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.EppXmlTransformer.marshal;
import static google.registry.model.eppcommon.EppXmlTransformer.marshal;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.POLL_MESSAGE_ID_STRIPPER;
import static google.registry.testing.DatastoreHelper.getPollMessages;

View file

@ -35,7 +35,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.googlecode.objectify.Key;
import google.registry.flows.EppException;
import google.registry.flows.EppXmlTransformer.IpAddressVersionMismatchException;
import google.registry.flows.FlowUtils.IpAddressVersionMismatchException;
import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.exceptions.ResourceAlreadyExistsException;
import google.registry.flows.host.HostCreateFlow.SubordinateHostMustHaveIpException;

View file

@ -45,7 +45,7 @@ public abstract class LoginFlowTestCase extends FlowTestCase<LoginFlow> {
@Before
public void initRegistrar() {
sessionMetadata.setClientId(null); // Don't implicitly log in (all other flows need to).
sessionMetadata.setClientId(null); // Don't implicitly log in (all other flows need to).
registrar = loadRegistrar("NewRegistrar");
registrarBuilder = registrar.asBuilder();
}

View file

@ -14,7 +14,7 @@
package google.registry.model;
import static google.registry.flows.EppXmlTransformer.marshalInput;
import static google.registry.model.eppcommon.EppXmlTransformer.marshalInput;
import static google.registry.xml.ValidationMode.STRICT;
import static google.registry.xml.XmlTestUtils.assertXmlEquals;
import static java.nio.charset.StandardCharsets.UTF_8;

View file

@ -14,8 +14,8 @@
package google.registry.model.contact;
import static google.registry.flows.EppXmlTransformer.marshalInput;
import static google.registry.flows.EppXmlTransformer.validateInput;
import static google.registry.model.eppcommon.EppXmlTransformer.marshalInput;
import static google.registry.model.eppcommon.EppXmlTransformer.validateInput;
import static google.registry.xml.ValidationMode.LENIENT;
import static google.registry.xml.XmlTestUtils.assertXmlEquals;
import static java.nio.charset.StandardCharsets.UTF_8;

View file

@ -12,11 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.flows;
package google.registry.model.eppcommon;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.EppXmlTransformer.unmarshal;
import static google.registry.model.eppcommon.EppXmlTransformer.unmarshal;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.TestDataHelper.loadBytes;
@ -41,8 +40,6 @@ public class EppXmlTransformerTest extends ShardableTestCase {
public void testUnmarshalingWrongClassThrows() {
assertThrows(
ClassCastException.class,
() ->
EppXmlTransformer.unmarshal(
EppOutput.class, loadBytes(getClass(), "contact_info.xml").read()));
() -> unmarshal(EppOutput.class, loadBytes(getClass(), "contact_info.xml").read()));
}
}

View file

@ -0,0 +1,14 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<info>
<contact:info
xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<contact:id>sh8013</contact:id>
<contact:authInfo>
<contact:pw>2fooBAR</contact:pw>
</contact:authInfo>
</contact:info>
</info>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -16,15 +16,15 @@ package google.registry.model.eppinput;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static google.registry.flows.EppXmlTransformer.unmarshal;
import static google.registry.model.eppcommon.EppXmlTransformer.unmarshal;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.TestDataHelper.loadBytes;
import google.registry.flows.EppException.SyntaxErrorException;
import google.registry.model.contact.ContactResourceTest;
import google.registry.model.domain.DomainResourceTest;
import google.registry.model.eppinput.EppInput.InnerCommand;
import google.registry.model.eppinput.EppInput.Login;
import google.registry.xml.XmlException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@ -83,7 +83,7 @@ public class EppInputTest {
@Test
public void testUnmarshalling_loginTagInWrongCase_throws() {
assertThrows(
SyntaxErrorException.class,
XmlException.class,
() -> unmarshal(EppInput.class, loadBytes(getClass(), "login_wrong_case.xml").read()));
}
}

View file

@ -20,7 +20,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import google.registry.flows.EppXmlTransformer;
import google.registry.model.eppcommon.EppXmlTransformer;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.eppinput.EppInput;
import google.registry.model.eppinput.EppInput.ResourceCommandWrapper;

View file

@ -16,7 +16,7 @@ package google.registry.testing;
import static com.google.common.truth.Truth.assertAbout;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.flows.EppXmlTransformer.marshal;
import static google.registry.model.eppcommon.EppXmlTransformer.marshal;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.SimpleSubjectBuilder;

View file

@ -14,7 +14,7 @@
package google.registry.testing;
import static google.registry.flows.EppXmlTransformer.unmarshal;
import static google.registry.flows.FlowUtils.unmarshalEpp;
import static google.registry.testing.TestDataHelper.loadFile;
import static java.nio.charset.StandardCharsets.UTF_8;
@ -37,7 +37,12 @@ public class EppLoader {
}
public EppInput getEpp() throws EppException {
return unmarshal(EppInput.class, eppXml.getBytes(UTF_8));
/*
* TODO(b/120837374): we shouldn't use EppException in non-Flow tests. Find a way to use {@link
* google.registry.model.eppcommon.EppXmlTransformer#unmarshal(Class, byte[])} in those tests
* instead of {@link google.registry.flows.FlowUtils#unmarshalEpp(Class, byte[])}
*/
return unmarshalEpp(EppInput.class, eppXml.getBytes(UTF_8));
}
public String getEppXml() {

View file

@ -16,12 +16,12 @@ package google.registry.tools;
import static com.google.common.io.BaseEncoding.base16;
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;
import static google.registry.model.domain.DesignatedContact.Type.TECH;
import static google.registry.model.domain.launch.ApplicationStatus.VALIDATED;
import static google.registry.model.eppcommon.EppXmlTransformer.unmarshal;
import static google.registry.model.registry.Registry.TldState.QUIET_PERIOD;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.newDomainApplication;