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
This commit is contained in:
mcilwain 2018-07-13 12:48:50 -07:00 committed by jianglai
parent df5d9957f7
commit 278ec2b289
5 changed files with 11 additions and 7 deletions

View file

@ -303,6 +303,7 @@ public class XmlTransformer {
try { try {
Transformer transformer = transformerFactory.newTransformer(); Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform( transformer.transform(
new StreamSource(new StringReader(xmlString)), new StreamSource(new StringReader(xmlString)),

View file

@ -132,7 +132,8 @@ public class FlowRunnerTest extends ShardableTestCase {
"TheRegistrar", "TheRegistrar",
"StatelessRequestSessionMetadata" "StatelessRequestSessionMetadata"
+ "{clientId=TheRegistrar, failedLoginAttempts=0, serviceExtensionUris=}", + "{clientId=TheRegistrar, failedLoginAttempts=0, serviceExtensionUris=}",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><xml/>", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>",
"<xml/>",
"", // Extra newline at the end of the XML. "", // Extra newline at the end of the XML.
"PasswordOnlyTransportCredentials{}", "PasswordOnlyTransportCredentials{}",
"UNIT_TEST", "UNIT_TEST",

View file

@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?><epp xmlns="urn:ietf:params:xml:ns:epp-1.0"> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command> <command>
<create> <create>
<domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> <domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">

View file

@ -17,6 +17,7 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static google.registry.xml.XmlTestUtils.assertXmlEquals; import static google.registry.xml.XmlTestUtils.assertXmlEquals;
import static google.registry.xml.XmlTransformer.prettyPrint;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Matchers.eq; import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.atLeast;
@ -191,9 +192,7 @@ public class EppToolVerifier {
private EppToolVerifier verifySentContents(String expectedXmlContent) throws Exception { private EppToolVerifier verifySentContents(String expectedXmlContent) throws Exception {
setArgumentsIfNeeded(); setArgumentsIfNeeded();
assertThat(capturedParams.size()).isGreaterThan(paramIndex); assertThat(capturedParams.size()).isGreaterThan(paramIndex);
assertXmlEquals( assertXmlEquals(expectedXmlContent, prettyPrint(bytesToXml(capturedParams.get(paramIndex))));
expectedXmlContent,
bytesToXml(capturedParams.get(paramIndex)));
paramIndex++; paramIndex++;
return this; return this;
} }

View file

@ -55,7 +55,8 @@ public class GetHistoryEntriesCommandTest extends CommandTestCase<GetHistoryEntr
+ "Time: 2000-01-01T00:00:00.000Z\n" + "Time: 2000-01-01T00:00:00.000Z\n"
+ "Client TRID: ABC-123\n" + "Client TRID: ABC-123\n"
+ "Server TRID: server-trid\n" + "Server TRID: server-trid\n"
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xml/>\n" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
+ "<xml/>\n"
+ "\n"); + "\n");
} }
@ -77,7 +78,8 @@ public class GetHistoryEntriesCommandTest extends CommandTestCase<GetHistoryEntr
+ "Time: 2000-01-01T00:00:00.000Z\n" + "Time: 2000-01-01T00:00:00.000Z\n"
+ "Client TRID: null\n" + "Client TRID: null\n"
+ "Server TRID: null\n" + "Server TRID: null\n"
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xml/>\n" + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
+ "<xml/>\n"
+ "\n"); + "\n");
} }
} }