use of com.gargoylesoftware.htmlunit.Page in project mvc-tck by mvc-spec.
the class SimpleAnnotatedTest method shouldDoStuff.
@Test
@SpecAssertion(section = "list-of-assertions", id = "Controller_Annotation")
public void shouldDoStuff() throws IOException {
Page page = new WebClient().getPage(baseUrl.toString() + "mvc/simple");
Assert.assertThat(page.getWebResponse().getContentAsString(), CoreMatchers.containsString("Hello world!"));
}
use of com.gargoylesoftware.htmlunit.Page in project spring-boot-quick by vector4wang.
the class test2 method main.
public static void main(String[] args) throws IOException {
// 创建WebClient
final WebClient webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(false);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setRedirectEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
Document parse = null;
Page page = null;
for (int i = 100; i < 1000; i++) {
try {
page = webClient.getPage("http://www.innotree.cn/company/" + i + ".html");
parse = Jsoup.parse(page.getWebResponse().getContentAsString());
Elements select = parse.select("body > div.details_1221_con > div.details_1221_d01 > div.details_1221_d01_01 > table > tbody > tr > td:nth-child(2) > h3");
System.out.println(select.get(0).text());
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of com.gargoylesoftware.htmlunit.Page in project spring-boot-quick by vector4wang.
the class Test method main.
public static void main(String[] args) throws IOException {
WebClient client = new WebClient(BrowserVersion.CHROME);
Page page = client.getPage("https://cas.baidu.com/?action=image&key=1497149653");
InputStream contentAsStream = page.getWebResponse().getContentAsStream();
IOUtils.copy(contentAsStream, new FileOutputStream(new File("d:\\bd.png")));
}
use of com.gargoylesoftware.htmlunit.Page in project tomee by apache.
the class FormAuthServletTest method authenticate.
@Test
public void authenticate() throws Exception {
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage(getAppUrl() + "/form");
assertEquals(200, page.getWebResponse().getStatusCode());
final HtmlForm login = page.getFormByName("login");
login.getInputByName("j_username").setValueAttribute("tomcat");
login.getInputByName("j_password").setValueAttribute("tomcat");
final Page result = login.getInputByName("submit").click();
assertEquals(200, result.getWebResponse().getStatusCode());
assertEquals("ok!", result.getWebResponse().getContentAsString());
assertEquals("ok!", webClient.getPage(getAppUrl() + "/form").getWebResponse().getContentAsString());
}
use of com.gargoylesoftware.htmlunit.Page in project blueocean-plugin by jenkinsci.
the class JwtAuthenticationServiceImplTest method anonymousUserToken.
@Test
public void anonymousUserToken() throws Exception {
j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
JenkinsRule.WebClient webClient = j.createWebClient();
String token = getToken(webClient);
Assert.assertNotNull(token);
JsonWebStructure jsonWebStructure = JsonWebStructure.fromCompactSerialization(token);
Assert.assertTrue(jsonWebStructure instanceof JsonWebSignature);
JsonWebSignature jsw = (JsonWebSignature) jsonWebStructure;
String kid = jsw.getHeader("kid");
Assert.assertNotNull(kid);
Page page = webClient.goTo("jwt-auth/jwks/" + kid + "/", "application/json");
// for(NameValuePair valuePair: page.getWebResponse().getResponseHeaders()){
// System.out.println(valuePair);
// }
JSONObject jsonObject = JSONObject.fromObject(page.getWebResponse().getContentAsString());
RsaJsonWebKey rsaJsonWebKey = new RsaJsonWebKey(jsonObject, null);
JwtConsumer jwtConsumer = new JwtConsumerBuilder().setRequireExpirationTime().setAllowedClockSkewInSeconds(// allow some leeway in validating time based claims to account for clock skew
30).setRequireSubject().setVerificationKey(// verify the sign with the public key
rsaJsonWebKey.getKey()).build();
JwtClaims claims = jwtConsumer.processToClaims(token);
Assert.assertEquals("anonymous", claims.getSubject());
Map<String, Object> claimMap = claims.getClaimsMap();
Map<String, Object> context = (Map<String, Object>) claimMap.get("context");
Map<String, String> userContext = (Map<String, String>) context.get("user");
Assert.assertEquals("anonymous", userContext.get("id"));
}
Aggregations