2016-05-05 53 views
0

我試圖用下面的XML來比較元素值CUSTOMER使用放心。我無法找到價值爲CUSTOMER的標籤。其他保證:驗證子標記的xml值

一旦我比較成功,我需要比較INVOICE, ITEM, PRODUCT以及其他細節。

<resource xmlns:xlink="http://www.w3.org/1999/xlink"> 
    <CUSTOMERList xlink:href="http://thomas-bayer.com/sqlrest/CUSTOMER/">CUSTOMER</CUSTOMERList> 
    <INVOICEList xlink:href="http://thomas-bayer.com/sqlrest/INVOICE/">INVOICE</INVOICEList> 
    <ITEMList xlink:href="http://thomas-bayer.com/sqlrest/ITEM/">**ITEM**</ITEMList> 
    <PRODUCTList xlink:href="http://thomas-bayer.com/sqlrest/PRODUCT/">PRODUCT</PRODUCTList> 
</resource> 

下面是我的代碼Java代碼:運行代碼後生成

RestAssured.baseURI = "http://thomas-bayer.com"; 
try { 
    RestAssured.given().parameter("CUSTOMERList") 
       .when().post("/sqlrest").then() 
       .body("resource.CUSTOMERList", Matchers.equalTo("CUSTOMER")); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

錯誤:

java.lang.AssertionError: XML path resource.CUSTOMERList doesn't match. 
Expected: CUSTOMER 

回答

2

您需要添加.text()檢索標記的值,如如下:

.body("resource.CUSTOMERList.text()", 
    Matchers.equalTo("CUSTOMER"));