- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中org.springframework.test.web.servlet.result.XpathResultMatchers.exists()
方法的一些代码示例,展示了XpathResultMatchers.exists()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XpathResultMatchers.exists()
方法的具体详情如下:
包路径:org.springframework.test.web.servlet.result.XpathResultMatchers
类名称:XpathResultMatchers
方法名:exists
[英]Evaluate the XPath and assert that content exists.
[中]评估XPath并断言内容存在。
代码示例来源: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(expected = AssertionError.class)
public void existsNoMatch() throws Exception {
new XpathResultMatchers("/foo/Bar", null).exists().match(getStubMvcResult());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void exists() throws Exception {
new XpathResultMatchers("/foo/bar", null).exists().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
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 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
void testLoginWithAnalytics(@Autowired MockMvc mockMvc) throws Exception {
mockMvc.perform(get("/login").accept(TEXT_HTML))
.andExpect(status().isOk())
.andExpect(xpath("//body/script[contains(text(),'example.com')]").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
@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
public void testNewAccountPage() throws Exception {
mockMvc.perform(get("/create_account").param("client_id", "client-id").param("redirect_uri", "http://example.com/redirect"))
.andExpect(status().isOk())
.andExpect(model().attribute("client_id", "client-id"))
.andExpect(model().attribute("redirect_uri", "http://example.com/redirect"))
.andExpect(view().name("accounts/new_activation_email"))
.andExpect(xpath("//*[@type='hidden' and @value='client-id']").exists())
.andExpect(xpath("//*[@type='hidden' and @value='http://example.com/redirect']").exists());
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void testChangeEmailPage() throws Exception {
setupSecurityContext();
mockMvc.perform(get("/change_email").param("client_id", "client-id").param("redirect_uri", "http://example.com/redirect"))
.andExpect(status().isOk())
.andExpect(view().name("change_email"))
.andExpect(model().attribute("email", "user@example.com"))
.andExpect(model().attribute("client_id", "client-id"))
.andExpect(model().attribute("redirect_uri", "http://example.com/redirect"))
.andExpect(xpath("//*[@type='hidden' and @value='client-id']").exists())
.andExpect(xpath("//*[@type='hidden' and @value='http://example.com/redirect']").exists());
}
代码示例来源: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 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 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: cloudfoundry/uaa
.andExpect(xpath("//a[text()='" + activeSamlIdentityProviderDefinition.getLinkText() + "']").exists())
.andExpect(xpath("//a[text()='" + inactiveSamlIdentityProviderDefinition.getLinkText() + "']").doesNotExist());
代码示例来源:origin: cloudfoundry/uaa
.andExpect(xpath("//a[text()='" + samlIdentityProviderDefinition.getLinkText() + "']").exists());
代码示例来源:origin: dschulten/hydra-java
@Test
public void testCreatesSimpleLinkForGetAffordanceWithoutRequestParams() throws Exception {
MvcResult result = this.mockMvc.perform(get("/events").accept(MediaType.TEXT_HTML))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.TEXT_HTML))
.andExpect(xpath("//h:a[@href='http://localhost/events/1']", namespaces).exists())
.andExpect(xpath("//h:a[@href='http://localhost/events/2']", namespaces).exists())
.andReturn();
LOG.debug(result.getResponse()
.getContentAsString());
}
代码示例来源:origin: dschulten/hydra-java
@Test
public void testCreatesHtmlFormForPost() throws Exception {
MvcResult result = this.mockMvc.perform(get("/events").accept(MediaType.TEXT_HTML))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.TEXT_HTML))
.andExpect(xpath("//h:form[@name='addEvent']/@action", namespaces).string("http://localhost/events"))
.andExpect(xpath("//h:form[@name='addEvent']/@method", namespaces).string("POST"))
.andExpect(xpath("//h:form[@name='addEvent']/h:div/h:select[@name='eventStatus']", namespaces).exists())
.andExpect(xpath("//h:form[@name='addEvent']/h:div/h:select[@name='typicalAgeRange']", namespaces)
.exists())
.andReturn();
LOG.debug(result.getResponse()
.getContentAsString());
}
代码示例来源:origin: dschulten/hydra-java
@Test
public void testCreatesHtmlFormForGet() throws Exception {
MvcResult result = this.mockMvc.perform(get("http://localhost/events").accept(MediaType.TEXT_HTML))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.TEXT_HTML))
.andExpect(xpath("//h:form[@action='http://localhost/events' and @method='GET' and " +
"@name='findEventByName']", namespaces).exists())
// TODO: form name
.andExpect(xpath("//h:form[@action='http://localhost/events' and @method='GET' and " +
"@name='findEventByName']/h:div/h:input/@name",
namespaces).string("evtName"))
.andReturn();
LOG.debug(result.getResponse()
.getContentAsString());
}
代码示例来源:origin: dschulten/hydra-java
@Test
public void testCreatesInputFieldWithMinMaxNumber() throws Exception {
MvcResult result = this.mockMvc.perform(get("/events").accept(MediaType.TEXT_HTML))
.andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.content()
.contentType(MediaType.TEXT_HTML))
.andExpect(xpath("//h:input[@name='reviewRating.ratingValue']", namespaces).exists())
.andExpect(xpath("//h:input[@name='reviewRating.ratingValue']/@type", namespaces).string("number"))
.andExpect(xpath("//h:input[@name='reviewRating.ratingValue']/@min", namespaces).string("1"))
.andExpect(xpath("//h:input[@name='reviewRating.ratingValue']/@max", namespaces).string("5"))
.andExpect(xpath("//h:input[@name='reviewRating.ratingValue']/@value", namespaces).string("3"))
.andReturn();
LOG.debug(result.getResponse()
.getContentAsString());
}
我有一个关于 Java Servlet 的问题。 假设我在 servlet 网页“somePage”上。我想登录(使用另一个 servlet,“登录”servlet)。所以我点击“somePage”上
如何将变量数组从一个 servlet 传递到另一个 servlet? 最佳答案 如果您要将当前请求传递给另一个servlet,则只需将其设置为请求属性即可。 request.setAttribute(
什么可能导致此错误? Caused by: jakarta.servlet.UnavailableException: Servlet class org.restlet.ext.servle
我的maven依赖树是这样的 我想问我maven如何解决这个冲突,有两个servlet-api.jar?提前谢谢你。 最佳答案 如果您想从 Velocity 工具中删除 servlet-api,您可以
config ProcessReg ProcessReg text HelloWorld1 public class config implements Serv
您好,我有一个关于 servlet 调用另一个 servlet 的问题 我有一个名为 Relay 的主 servlet,它将负责控制其他 servlet 用户将点击并将转发到 Relay servle
在我的 REST API 项目中,我已将 /* 映射到 RESTServlet,并且需要在同一 WAR 中托管静态内容。我更愿意将 /static/* 映射到 WAS liberty 提供的默认 se
响应映射在 Servlet 中如何工作? 每个响应如何知道清除特定 HTML 或 Handlebars 上的输出? 最佳答案 有一个 ember-java带有 Jersey REST 服务 的 git
有一个 @WebServlet(urlPatterns = "/myServlet/") .如果用户转到 myapp/myServlet/other ,我仍然希望我的 servlet 能够捕获。也就是
我正在使用 Filter 在我的所有页面中插入反点击劫持 header - 这工作正常,除了 JBoss EAP 6.3 容器管理的登录页面,这是更重要的页面之一拥有它。 登录页面根本不调用过滤器,登
我正在尝试使用 RequestDispatcher 将数据从一个 servlet 传递到另一个 servlet。这是我的调度程序代码。 String address; address = "/Java
我刚刚开始使用 Servlet,并设法让一些 Servlet 充当单独的 URL,用于填充数据库以进行一些虚拟测试。某种形式: public class Populate_ServletName ex
我是否需要同时配置app.servlet.version 和 grails.servlet.version? 前者在application.properties中,后者在BuildConfig.gro
在Myeclipse中我创建了一个名为web1的Web项目,并添加了一个名为servlet1的servlet,web.xml如下: servlet1 servlet1
这个问题在这里已经有了答案: How to run a background task in a servlet based web application? (5 个回答) 6年前关闭。 是否可以在
在我的 ManagedBean 中,如果我将范围从 @RequestScoped 更改为 @ViewScoped,我将收到以下错误堆栈。我该如何解决这个问题?不过,当我运行应用程序时,我可以在页面中看
这个问题已经有答案了: How do I execute multiple servlets in sequence? (2 个回答) 已关闭 3 年前。 我已经构建了jdbc-Servlet的代码,
我一直在徒劳地尝试实现 tomcat 9 的 jakarta servlet,而不是以前的 javax.servlet 实现(因为我的理解是 jakarta 包是前进的方向)。问题是,当我将浏览器指向
我是 Spring 新手,正在尝试使用 Maven 部署和运行我的第一个 Spring Web 应用程序。有关更多详细信息,请参阅 here (我昨天发布的一个问题): 现在,我遇到的问题是:当我尝试
我正在尝试学习如何使用 JSP。我遇到了一些毫无意义的事情,至少在我看来是这样: 当我尝试运行时: response.getWriter().println(m.getDb().printAll())
我是一名优秀的程序员,十分优秀!