gpt4 book ai didi

org.springframework.test.web.servlet.result.XpathResultMatchers类的使用及代码示例

转载 作者:知者 更新时间:2024-03-21 01:09:05 28 4
gpt4 key购买 nike

本文整理了Java中org.springframework.test.web.servlet.result.XpathResultMatchers类的一些代码示例,展示了XpathResultMatchers类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XpathResultMatchers类的具体详情如下:
包路径:org.springframework.test.web.servlet.result.XpathResultMatchers
类名称: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());
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com