From 278ec2b289d55a6a640fcae170ba137cf65b8ce1 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Fri, 13 Jul 2018 12:48:50 -0700 Subject: [PATCH] Pretty-print actual XML in tests This means that, when writing new tests that are failing, you get much more useful logs that show the actual XML in a more comprehensible format that is suitable for pasting back into the golden file in the test (if the change was intended). This requires outputting the standalone parameter in the XML transformer, and some minor changes to some tests as a result that were relying on it being stripped out. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=204513690 --- java/google/registry/xml/XmlTransformer.java | 1 + javatests/google/registry/flows/FlowRunnerTest.java | 3 ++- .../registry/flows/testdata/domain_create_prettyprinted.xml | 3 ++- javatests/google/registry/tools/EppToolVerifier.java | 5 ++--- .../google/registry/tools/GetHistoryEntriesCommandTest.java | 6 ++++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/java/google/registry/xml/XmlTransformer.java b/java/google/registry/xml/XmlTransformer.java index 30b0b8cb9..6ccd5713c 100644 --- a/java/google/registry/xml/XmlTransformer.java +++ b/java/google/registry/xml/XmlTransformer.java @@ -303,6 +303,7 @@ public class XmlTransformer { try { Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty(OutputKeys.STANDALONE, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform( new StreamSource(new StringReader(xmlString)), diff --git a/javatests/google/registry/flows/FlowRunnerTest.java b/javatests/google/registry/flows/FlowRunnerTest.java index 1995be773..e9772765e 100644 --- a/javatests/google/registry/flows/FlowRunnerTest.java +++ b/javatests/google/registry/flows/FlowRunnerTest.java @@ -132,7 +132,8 @@ public class FlowRunnerTest extends ShardableTestCase { "TheRegistrar", "StatelessRequestSessionMetadata" + "{clientId=TheRegistrar, failedLoginAttempts=0, serviceExtensionUris=}", - "", + "", + "", "", // Extra newline at the end of the XML. "PasswordOnlyTransportCredentials{}", "UNIT_TEST", diff --git a/javatests/google/registry/flows/testdata/domain_create_prettyprinted.xml b/javatests/google/registry/flows/testdata/domain_create_prettyprinted.xml index 785c293be..eebc36788 100644 --- a/javatests/google/registry/flows/testdata/domain_create_prettyprinted.xml +++ b/javatests/google/registry/flows/testdata/domain_create_prettyprinted.xml @@ -1,4 +1,5 @@ - + + diff --git a/javatests/google/registry/tools/EppToolVerifier.java b/javatests/google/registry/tools/EppToolVerifier.java index 31e12e690..f2b95917a 100644 --- a/javatests/google/registry/tools/EppToolVerifier.java +++ b/javatests/google/registry/tools/EppToolVerifier.java @@ -17,6 +17,7 @@ package google.registry.tools; import static com.google.common.base.Preconditions.checkState; import static com.google.common.truth.Truth.assertThat; import static google.registry.xml.XmlTestUtils.assertXmlEquals; +import static google.registry.xml.XmlTransformer.prettyPrint; import static java.nio.charset.StandardCharsets.UTF_8; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.atLeast; @@ -191,9 +192,7 @@ public class EppToolVerifier { private EppToolVerifier verifySentContents(String expectedXmlContent) throws Exception { setArgumentsIfNeeded(); assertThat(capturedParams.size()).isGreaterThan(paramIndex); - assertXmlEquals( - expectedXmlContent, - bytesToXml(capturedParams.get(paramIndex))); + assertXmlEquals(expectedXmlContent, prettyPrint(bytesToXml(capturedParams.get(paramIndex)))); paramIndex++; return this; } diff --git a/javatests/google/registry/tools/GetHistoryEntriesCommandTest.java b/javatests/google/registry/tools/GetHistoryEntriesCommandTest.java index 4b74dd854..fc17977a1 100644 --- a/javatests/google/registry/tools/GetHistoryEntriesCommandTest.java +++ b/javatests/google/registry/tools/GetHistoryEntriesCommandTest.java @@ -55,7 +55,8 @@ public class GetHistoryEntriesCommandTest extends CommandTestCase\n" + + "\n" + + "\n" + "\n"); } @@ -77,7 +78,8 @@ public class GetHistoryEntriesCommandTest extends CommandTestCase\n" + + "\n" + + "\n" + "\n"); } }