我正在运行测试以验证到达端点的XML是否与文件中包含的XML相同。我正在运行assertMockEndpointsSatisfied()
并使用其他工具验证XML是相同的。
String sourceXml = readFile("src/test/resources/source1.xml");
String targetXml = readFile("src/test/resources/target1.xml");
// Mock WS endpoint should receive one message
mockResult.expectedMessageCount(1);
// Target endpoint should receive the target XML
mockResult.expectedBodiesReceived(targetXml);
// Start the process by sending in the Source XML
start.sendBody(sourceXml);
// Run all assertions
assertMockEndpointsSatisfied();
并且失败(已修改的元素和名称空间)正在读取:
java.lang.AssertionError: mock://jmsamq:queue:SettlementOut Body of message: 0. Expected: <<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<api:req xmlns="testNS" xmlns:api="testAPI">
<api:test>
<a>0600017121</a>
<b>01</b>
<c>1000.50</c>
<d>2000</d>
</api:test>
</api:req>
> but was: <<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<api:req xmlns="testNS" xmlns:api="testAPI">
<api:test>
<a>0600017121</a>
<b>01</b>
<c>1000.50</c>
<d>2000</d>
</api:test>
</api:req>
>
我考虑过XMLUnit,但不想这样做。当我使用'\ n'而不是新行和4个空格与字符串而不是文件进行比较时,它可以正常工作。
答案 0 :(得分:0)
您正在使用的内置功能将XML完全与其逻辑内容进行比较。我必须编写自己的使用XMLUnit的包装器,我提供但我的前雇主现在拥有它。 :(