- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中org.springframework.test.web.servlet.result.XpathResultMatchers.string()
方法的一些代码示例,展示了XpathResultMatchers.string()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XpathResultMatchers.string()
方法的具体详情如下:
包路径:org.springframework.test.web.servlet.result.XpathResultMatchers
类名称:XpathResultMatchers
方法名:string
[英]Apply the XPath and assert the String value found.
[中]应用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 string() throws Exception {
new XpathResultMatchers("/foo/bar[1]", null).string("111").match(getStubMvcResult());
}
代码示例来源:origin: spring-projects/spring-framework
@Test(expected = AssertionError.class)
public void stringNoMatch() throws Exception {
new XpathResultMatchers("/foo/bar[1]", null).string("112").match(getStubMvcResult());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void stringEncodingDetection() throws Exception {
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<person><name>Jürgen</name></person>";
byte[] bytes = content.getBytes(StandardCharsets.UTF_8);
MockHttpServletResponse response = new MockHttpServletResponse();
response.addHeader("Content-Type", "application/xml");
StreamUtils.copy(bytes, response.getOutputStream());
StubMvcResult result = new StubMvcResult(null, null, null, null, null, null, response);
new XpathResultMatchers("/person/name", null).string("Jürgen").match(result);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testFeedWithLinefeedChars() throws Exception {
// Map<String, String> namespace = Collections.singletonMap("ns", "");
standaloneSetup(new BlogFeedController()).build()
.perform(get("/blog.atom").accept(MediaType.APPLICATION_ATOM_XML))
.andExpect(status().isOk())
.andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_ATOM_XML))
.andExpect(xpath("//feed/title").string("Test Feed"))
.andExpect(xpath("//feed/icon").string("http://www.example.com/favicon.ico"));
}
代码示例来源: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: spring-projects/spring-framework
@Test
public void testXmlOnly() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(Person.class);
standaloneSetup(new PersonController()).setSingleView(new MarshallingView(marshaller)).build()
.perform(get("/person/Corea"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_XML))
.andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
}
代码示例来源: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());
}
代码示例来源:origin: cloudfoundry/uaa
@Test
void testActivationEmailSentPage() throws Exception {
mockMvc.perform(get("/accounts/email_sent"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Create your account")))
.andExpect(xpath("//input[@disabled='disabled']/@value").string("Email successfully sent"));
}
代码示例来源: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
void testActivationEmailSentPageWithinZone() throws Exception {
String subdomain = generator.generate();
MockMvcUtils.createOtherIdentityZone(subdomain, mockMvc, webApplicationContext);
mockMvc.perform(get("/accounts/email_sent")
.with(new SetServerNameRequestPostProcessor(subdomain + ".localhost")))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Create your account")))
.andExpect(xpath("//input[@disabled='disabled']/@value").string("Email successfully sent"))
.andExpect(content().string(containsString("Cloud Foundry")));
}
代码示例来源:origin: cloudfoundry/uaa
@Test
void testSignupsAndResetPasswordEnabledWithCustomLinks() throws Exception {
identityZoneConfiguration.getLinks().getSelfService().setSignup("http://example.com/signup");
identityZoneConfiguration.getLinks().getSelfService().setPasswd("http://example.com/reset_passwd");
identityZoneConfiguration.getLinks().getSelfService().setSelfServiceLinksEnabled(true);
MockMvcUtils.setZoneConfiguration(webApplicationContext, getUaa().getId(), identityZoneConfiguration);
mockMvc.perform(MockMvcRequestBuilders.get("/login"))
.andExpect(xpath("//a[text()='Create account']/@href").string("http://example.com/signup"))
.andExpect(xpath("//a[text()='Reset password']/@href").string("http://example.com/reset_passwd"));
}
代码示例来源:origin: cloudfoundry/uaa
@Test
void idpDiscoveryPageDisplayed_IfFlagIsEnabled(
@Autowired IdentityZoneProvisioning identityZoneProvisioning
) throws Exception {
IdentityZoneConfiguration config = new IdentityZoneConfiguration();
config.setIdpDiscoveryEnabled(true);
IdentityZone zone = setupZone(webApplicationContext, mockMvc, identityZoneProvisioning, generator, config);
mockMvc.perform(get("/login")
.header("Accept", TEXT_HTML)
.with(new SetServerNameRequestPostProcessor(zone.getSubdomain() + ".localhost")))
.andExpect(status().isOk())
.andExpect(view().name("idp_discovery/email"))
.andExpect(content().string(containsString("Sign in")))
.andExpect(xpath("//input[@name='email']").exists())
.andExpect(xpath("//div[@class='action']//a").string("Create account"))
.andExpect(xpath("//input[@name='commit']/@value").string("Next"));
}
代码示例来源: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
void ifInvalidOrExpiredCode_goTo_createAccountDefaultPage() throws Exception {
mockMvc.perform(get("/verify_user")
.param("code", "expired-code"))
.andExpect(status().isUnprocessableEntity())
.andExpect(model().attribute("error_message_code", "code_expired"))
.andExpect(view().name("accounts/link_prompt"))
.andExpect(xpath("//a[text()='here']/@href").string("/create_account"));
}
代码示例来源:origin: cloudfoundry/uaa
@Test
void passwordPageDisplayed_ifUaaIsFallbackIDPForEmailDomain(
@Autowired IdentityZoneProvisioning identityZoneProvisioning
) throws Exception {
IdentityZoneConfiguration config = new IdentityZoneConfiguration();
config.setIdpDiscoveryEnabled(true);
IdentityZone zone = setupZone(webApplicationContext, mockMvc, identityZoneProvisioning, generator, config);
mockMvc.perform(post("/login/idp_discovery")
.header("Accept", TEXT_HTML)
.with(cookieCsrf())
.with(new SetServerNameRequestPostProcessor(zone.getSubdomain() + ".localhost"))
.param("email", "marissa@koala.com"))
.andExpect(status().isFound())
.andExpect(redirectedUrl("/login?discoveryPerformed=true&email=marissa%40koala.com"));
mockMvc.perform(get("/login?discoveryPerformed=true&email=marissa@koala.com")
.with(cookieCsrf())
.with(new SetServerNameRequestPostProcessor(zone.getSubdomain() + ".localhost"))
.header("Accept", TEXT_HTML))
.andExpect(view().name("idp_discovery/password"))
.andExpect(xpath("//input[@name='password']").exists())
.andExpect(xpath("//input[@name='username']/@value").string("marissa@koala.com"))
.andExpect(xpath("//div[@class='action pull-right']//a").string("Reset password"))
.andExpect(xpath("//input[@type='submit']/@value").string("Sign in"));
}
代码示例来源:origin: spring-projects/spring-framework
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_XML))
.andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
代码示例来源:origin: cloudfoundry/uaa
@Test
void ifInvalidOrExpiredCode_withNonDefaultSignupLinkProperty_goToNonDefaultSignupPage() throws Exception {
String signUpLink = "http://mypage.com/signup";
setProperty("links.signup", signUpLink);
mockMvc.perform(get("/verify_user")
.param("code", "expired-code"))
.andExpect(status().isUnprocessableEntity())
.andExpect(model().attribute("error_message_code", "code_expired"))
.andExpect(view().name("accounts/link_prompt"))
.andExpect(xpath("//a[text()='here']/@href").string(signUpLink));
}
代码示例来源:origin: cloudfoundry/uaa
@Test
void idpDiscoveryClientNameDisplayed_WithUTF8Characters(
@Autowired IdentityZoneProvisioning identityZoneProvisioning
) throws Exception {
String utf8String = "\u7433\u8D3A";
String clientName = "woohoo-" + utf8String;
IdentityZoneConfiguration config = new IdentityZoneConfiguration();
config.setIdpDiscoveryEnabled(true);
IdentityZone zone = setupZone(webApplicationContext, mockMvc, identityZoneProvisioning, generator, config);
MockHttpSession session = new MockHttpSession();
String clientId = generator.generate();
BaseClientDetails client = new BaseClientDetails(clientId, "", "", "client_credentials", "uaa.none", "http://*.wildcard.testing,http://testing.com");
client.setClientSecret("secret");
client.addAdditionalInformation(ClientConstants.CLIENT_NAME, clientName);
MockMvcUtils.createClient(webApplicationContext, client, zone);
SavedRequest savedRequest = getSavedRequest(client);
session.setAttribute(SAVED_REQUEST_SESSION_ATTRIBUTE, savedRequest);
mockMvc.perform(get("/login")
.session(session)
.header("Accept", TEXT_HTML)
.with(new SetServerNameRequestPostProcessor(zone.getSubdomain() + ".localhost")))
.andExpect(status().isOk())
.andExpect(view().name("idp_discovery/email"))
.andExpect(content().string(containsString("Sign in to continue to " + clientName)))
.andExpect(xpath("//input[@name='email']").exists())
.andExpect(xpath("//div[@class='action']//a").string("Create account"))
.andExpect(xpath("//input[@name='commit']/@value").string("Next"));
}
代码示例来源:origin: cloudfoundry/uaa
@Test
void userNamePresentInPasswordPage(
@Autowired IdentityZoneProvisioning identityZoneProvisioning
) throws Exception {
IdentityZoneConfiguration config = new IdentityZoneConfiguration();
config.setIdpDiscoveryEnabled(true);
IdentityZone zone = setupZone(webApplicationContext, mockMvc, identityZoneProvisioning, generator, config);
mockMvc.perform(post("/login/idp_discovery")
.with(cookieCsrf())
.param("email", "test@email.com")
.with(new SetServerNameRequestPostProcessor(zone.getSubdomain() + ".localhost")))
.andExpect(status().isFound())
.andExpect(redirectedUrl("/login?discoveryPerformed=true&email=test%40email.com"));
mockMvc.perform(get("/login?discoveryPerformed=true&email=test@email.com")
.with(cookieCsrf())
.with(new SetServerNameRequestPostProcessor(zone.getSubdomain() + ".localhost")))
.andExpect(xpath("//input[@name='username']/@value").string("test@email.com"));
}
本文整理了Java中org.springframework.test.web.servlet.result.XpathResultMatchers.doesNotExist()方法的一些代码示例,展示
本文整理了Java中org.springframework.test.web.servlet.result.XpathResultMatchers.string()方法的一些代码示例,展示了Xpath
本文整理了Java中org.springframework.test.web.servlet.result.XpathResultMatchers.()方法的一些代码示例,展示了XpathResult
本文整理了Java中org.springframework.test.web.servlet.result.XpathResultMatchers.getDefinedEncoding()方法的一些代
本文整理了Java中org.springframework.test.web.servlet.result.XpathResultMatchers.exists()方法的一些代码示例,展示了Xpath
我是一名优秀的程序员,十分优秀!