- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中org.springframework.test.web.servlet.result.XpathResultMatchers
类的一些代码示例,展示了XpathResultMatchers
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XpathResultMatchers
类的具体详情如下:
包路径:org.springframework.test.web.servlet.result.XpathResultMatchers
类名称:XpathResultMatchers
[英]Factory for assertions on the response content using XPath expressions.
An instance of this class is typically accessed via MockMvcResultMatchers#xpath.
[中]使用XPath表达式对响应内容进行断言的工厂。
此类的实例通常通过MockMvcResultMatchers#xpath访问。
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testString() throws Exception {
String composerName = "/ns:people/composers/composer[%s]/name";
String performerName = "/ns:people/performers/performer[%s]/name";
this.mockMvc.perform(get("/music/people"))
.andExpect(xpath(composerName, musicNamespace, 1).string("Johann Sebastian Bach"))
.andExpect(xpath(composerName, musicNamespace, 2).string("Johannes Brahms"))
.andExpect(xpath(composerName, musicNamespace, 3).string("Edvard Grieg"))
.andExpect(xpath(composerName, musicNamespace, 4).string("Robert Schumann"))
.andExpect(xpath(performerName, musicNamespace, 1).string("Vladimir Ashkenazy"))
.andExpect(xpath(performerName, musicNamespace, 2).string("Yehudi Menuhin"))
.andExpect(xpath(composerName, musicNamespace, 1).string(equalTo("Johann Sebastian Bach"))) // Hamcrest..
.andExpect(xpath(composerName, musicNamespace, 1).string(startsWith("Johann")))
.andExpect(xpath(composerName, musicNamespace, 1).string(notNullValue()));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void exists() throws Exception {
new XpathResultMatchers("/foo/bar", null).exists().match(getStubMvcResult());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void doesNotExist() throws Exception {
new XpathResultMatchers("/foo/Bar", null).doesNotExist().match(getStubMvcResult());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void string() throws Exception {
new XpathResultMatchers("/foo/bar[1]", null).string("111").match(getStubMvcResult());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void node() throws Exception {
new XpathResultMatchers("/foo/bar", null).node(Matchers.notNullValue()).match(getStubMvcResult());
}
代码示例来源:origin: cloudfoundry/uaa
@Test
void testExternalizedBranding(@Autowired MockMvc mockMvc) throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/login"))
.andExpect(xpath("//head/link[@rel='shortcut icon']/@href").string("//cdn.example.com/pivotal/images/square-logo.png"))
.andExpect(xpath("//head/link[@href='//cdn.example.com/pivotal/stylesheets/application.css']").exists())
.andExpect(xpath("//head/style[text()[contains(.,'//cdn.example.com/pivotal/images/product-logo.png')]]").exists());
}
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void tilesFromClientMetadataAndTilesConfigShown() throws Exception {
mockMvc.perform(get("/"))
.andExpect(xpath("//*[@id='tile-1'][text()[contains(.,'client-1')]]").exists())
.andExpect(xpath("//*[@class='tile-1']/@href").string("http://app.launch/url"))
.andExpect(xpath("//head/style[2]").string(".tile-1 .tile-icon {background-image: url(\"data:image/png;base64," + base64EncodedImg + "\")}"))
.andExpect(xpath("//*[@id='tile-2'][text()[contains(.,'Client 2 Name')]]").exists())
.andExpect(xpath("//*[@class='tile-2']/@href").string("http://second.url/"))
.andExpect(xpath("//*[@class='tile-3']").doesNotExist());
}
代码示例来源:origin: cloudfoundry/uaa
.andExpect(xpath("//a[text()='" + activeSamlIdentityProviderDefinition.getLinkText() + "']").exists())
.andExpect(xpath("//a[text()='" + inactiveSamlIdentityProviderDefinition.getLinkText() + "']").doesNotExist());
代码示例来源:origin: spring-projects/spring-framework
/**
* Apply the XPath and assert the {@link String} value found.
*/
public ResultMatcher string(final String expectedValue) {
return result -> {
MockHttpServletResponse response = result.getResponse();
this.xpathHelper.assertString(response.getContentAsByteArray(), getDefinedEncoding(response), expectedValue);
};
}
代码示例来源:origin: cloudfoundry/uaa
@Test
void testSignupsAndResetPasswordEnabled() throws Exception {
MockMvcUtils.setSelfServiceLinksEnabled(webApplicationContext, getUaa().getId(), true);
mockMvc.perform(MockMvcRequestBuilders.get("/login"))
.andExpect(xpath("//a[text()='Create account']").exists())
.andExpect(xpath("//a[text()='Reset password']").exists());
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void testAcceptInvitePageWithExpiredCode() throws Exception {
when(expiringCodeStore.retrieveCode(anyString(), eq(IdentityZoneHolder.get().getId()))).thenReturn(null);
MockHttpServletRequestBuilder get = get("/invitations/accept").param("code", "the_secret_code");
mockMvc.perform(get)
.andExpect(status().isUnprocessableEntity())
.andExpect(model().attribute("error_message_code", "code_expired"))
.andExpect(view().name("invitations/accept_invite"))
.andExpect(xpath("//*[@class='email-display']").doesNotExist())
.andExpect(xpath("//form").doesNotExist());
assertNull(SecurityContextHolder.getContext().getAuthentication());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Access to response body assertions using an XPath expression to
* inspect a specific subset of the body.
* <p>The XPath expression can be a parameterized string using formatting
* specifiers as defined in {@link String#format(String, Object...)}.
* @param expression the XPath expression, optionally parameterized with arguments
* @param args arguments to parameterize the XPath expression with
*/
public static XpathResultMatchers xpath(String expression, Object... args) throws XPathExpressionException {
return new XpathResultMatchers(expression, null, args);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testExists() throws Exception {
String composer = "/ns:people/composers/composer[%s]";
String performer = "/ns:people/performers/performer[%s]";
this.mockMvc.perform(get("/music/people"))
.andExpect(xpath(composer, musicNamespace, 1).exists())
.andExpect(xpath(composer, musicNamespace, 2).exists())
.andExpect(xpath(composer, musicNamespace, 3).exists())
.andExpect(xpath(composer, musicNamespace, 4).exists())
.andExpect(xpath(performer, musicNamespace, 1).exists())
.andExpect(xpath(performer, musicNamespace, 2).exists())
.andExpect(xpath(composer, musicNamespace, 1).node(notNullValue()));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void booleanValue() throws Exception {
new XpathResultMatchers("/foo/bar[2]", null).booleanValue(true).match(getStubMvcResult());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void nodeCount() throws Exception {
new XpathResultMatchers("/foo/bar", null).nodeCount(2).match(getStubMvcResult());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void number() throws Exception {
new XpathResultMatchers("/foo/bar[1]", null).number(111.0).match(getStubMvcResult());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testDoesNotExist() throws Exception {
String composer = "/ns:people/composers/composer[%s]";
String performer = "/ns:people/performers/performer[%s]";
this.mockMvc.perform(get("/music/people"))
.andExpect(xpath(composer, musicNamespace, 0).doesNotExist())
.andExpect(xpath(composer, musicNamespace, 5).doesNotExist())
.andExpect(xpath(performer, musicNamespace, 0).doesNotExist())
.andExpect(xpath(performer, musicNamespace, 3).doesNotExist())
.andExpect(xpath(composer, musicNamespace, 0).node(nullValue()));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testBoolean() throws Exception {
String performerBooleanValue = "/ns:people/performers/performer[%s]/someBoolean";
this.mockMvc.perform(get("/music/people"))
.andExpect(xpath(performerBooleanValue, musicNamespace, 1).booleanValue(false))
.andExpect(xpath(performerBooleanValue, musicNamespace, 2).booleanValue(true));
}
代码示例来源:origin: cloudfoundry/uaa
@Test
void testDefaultBranding() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/login"))
.andExpect(xpath("//head/link[@rel='shortcut icon']/@href").string("/resources/oss/images/square-logo.png"))
.andExpect(xpath("//head/link[@href='/resources/oss/stylesheets/application.css']").exists())
.andExpect(xpath("//head/style[text()[contains(.,'/resources/oss/images/product-logo.png')]]").exists());
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void tilesFromClientMetadataAndTilesConfigShown_forOtherZone() throws Exception {
IdentityZone identityZone = MultitenancyFixture.identityZone("test", "test");
IdentityZoneHolder.set(identityZone);
mockMvc.perform(get("/"))
.andExpect(xpath("//*[@id='tile-1'][text()[contains(.,'client-1')]]").exists())
.andExpect(xpath("//*[@class='tile-1']/@href").string("http://app.launch/url"))
.andExpect(xpath("//head/style[1]").string(".tile-1 .tile-icon {background-image: url(\"data:image/png;base64," + base64EncodedImg + "\")}"))
.andExpect(xpath("//*[@id='tile-2'][text()[contains(.,'Client 2 Name')]]").exists())
.andExpect(xpath("//*[@class='tile-2']/@href").string("http://second.url/"))
.andExpect(xpath("//*[@class='tile-3']").doesNotExist());
}
我有点困惑为什么在 RoutineRetrieved 函数中分配 ACTIVITYIMAGE 时使用 result.getInt(2) 并在分配 SLOT 时使用 result.getInt(3)..
我是android领域的新手,我想从响应json数组访问每个结果元素,但我无法做到这一点,我试图获取每个元素,但我只得到一个值“rohit1”是第一个元素。请帮助我。 我是 rohit parmar,
我只有从 sql 查询返回的一行 (count(*)),但在执行包时,它向我显示上述错误,并且包失败。 我将结果类型设置为“单行”,并将查询的输出(select count(*) as 'result
我正在尝试使用Diesel将简单的原始SQL转换为MySQL,如本示例所示: https://docs.diesel.rs/diesel/fn.sql_query.html let users = s
我正在尝试 Play 框架的第一个示例,但出现了此错误 在我的路线文件中: # API # ~~~~ GET /api/geotweets/index controllers.api.GeoTw
这段代码可以返回null吗? (this.Result == Result.OK) 此行(或类似行)是否可以返回除 true 或 false 之外的任何内容(例如 null)? 最佳答案 (this.
我有一个 SSIS 执行 SQL 任务。它返回一个完整的结果集(即一个表)。但是,当我执行包时出现以下错误。我已经正确地为返回的结果集命名。 [执行 SQL 任务] 错误:对于完整的结果集和 XML
最近我刚刚将 swift 2.3 项目转换为 3.2,alamofire 也得到了转换,我收到了很多问题,其中大部分都已解决,现在我被给定的两个问题所困扰 问题在 alamofire 的 Respon
我在 R 中收到以下错误消息: Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set", : Unable to r
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 去年关闭。
我正在使用一个简单的命令运行以下存储过程sp_MSforeachdb。我的问题是如何限制结果仅显示至少有 1 条记录满足命令的数据库: 这是我的存储过程: EXECUTE master.sys.sp_
我在单独的线程中运行一些代码: fn f1() -> Result { Err("err1".to_string()) } fn f2() -> Result { Err("err2"
我在这里尝试使用 AsyncTask 从 OWM API 显示 7 天的天气预报。 doInBackground(String...param) 方法也工作正常。我检查了 LOGCAT。 异步完成执行
我已经创建了mysql的索引和全文索引,后端存储引擎是MyISAM。 mysql> show index from play_movie; +------------+------------+---
我有一个表articles,它的结构如下: id, name, date, contents 我有一个表authors,它的结构如下: id, article_id, name, email 一篇文章
我很困惑我们是否应该创建单独的 API 来获取结果和结果计数,或者我们应该只根据结果 API 中的查询字符串来获取计数。 /api/results/ : Fetches all records /ap
我正在制作一个将两个数字相除的系统,如果第二个数字不存在,它将选择第一个数字。这是代码: let new_num: f32 = match num1/num2 { Ok(num) => n
这个问题在这里已经有了答案: Why am I getting "unused Result which must be used ... Result may be an Err variant,
我正在修改 the texture synth 中的示例之一项目: use texture_synthesis as ts; fn main() -> Result { //create a
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: ^ operator in java 我假设 c ^ d是一个类似“的幂”的计算,所以c = 5 , d = 2 ,
我是一名优秀的程序员,十分优秀!