Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何为Junit测试用例编写xPath_Xml_Spring Mvc_Xpath_Junit_Mockito - Fatal编程技术网

Xml 如何为Junit测试用例编写xPath

Xml 如何为Junit测试用例编写xPath,xml,spring-mvc,xpath,junit,mockito,Xml,Spring Mvc,Xpath,Junit,Mockito,我有以下XML字符串, 如何编写XPath以获取值“rest/accounts/123” 但是线路 MockMvcResultMatchers.xpath(“/account/atom:link/href()”)字符串( Matchers.containssString(“/rest/accounts/123”)) 是投掷错误 根据建议,我将代码更改为 mockMvc.perform( MockMvcRequestBuilders.get("/rest/acco

我有以下XML字符串, 如何编写XPath以获取值“rest/accounts/123”

但是线路

MockMvcResultMatchers.xpath(“/account/atom:link/href()”)字符串( Matchers.containssString(“/rest/accounts/123”))

是投掷错误

根据建议,我将代码更改为

 mockMvc.perform(
                MockMvcRequestBuilders.get("/rest/accounts/123").contentType(MediaType.APPLICATION_JSON)
                        .accept(MediaType.APPLICATION_XML))

                .andDo(print())
                .andExpect(MockMvcResultMatchers.status().isOk())
                .andExpect(
                        MockMvcResultMatchers.xpath("/account/atom:link/@href,").string(
                                Matchers.containsString("/rest/accounts/123")))
                .andExpect(MockMvcResultMatchers.xpath("/account/name/text()").string(Matchers.equalTo("satya")));

        // .andExpect(MockMvcResultMatchers.jsonPath("$.links[*].href").exists());
    }
Junit测试用例给出错误

com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception: 前缀必须解析为名称空间:atom


您可以使用
后的
子字符串功能:

substring-after(//atom:link/@href, "http://localhost/")

您可以使用
后的
子字符串功能:

substring-after(//atom:link/@href, "http://localhost/")

添加上述更改后,仍然会出现Junit测试用例错误,如中所示problem@Satya当前位置我不熟悉您使用的库。我回答了原来的问题。也许您需要注册
atom
名称空间?添加上述更改后,仍然会出现Junit测试用例错误,如中所示problem@Satya当前位置我不熟悉您使用的库。我回答了原来的问题。也许您需要注册
atom
名称空间?
substring-after(//atom:link/@href, "http://localhost/")