use of com.gargoylesoftware.htmlunit.WebRequest in project javaee7-samples by javaee-samples.
the class SecureServletTest method testPostWithCorrectCredentials.
@Test
public void testPostWithCorrectCredentials() throws Exception {
webClient.setCredentialsProvider(correctCreds);
WebRequest request = new WebRequest(new URL(base + "SecureServlet"), POST);
TextPage page = webClient.getPage(request);
assertEquals("my POST", page.getContent());
}
use of com.gargoylesoftware.htmlunit.WebRequest in project javaee7-samples by javaee-samples.
the class SecureServletTest method testPostWithIncorrectCredentials.
@Test
public void testPostWithIncorrectCredentials() throws Exception {
System.out.println("\n\n\nStarting testPostWithIncorrectCredentials\n\n");
webClient.setCredentialsProvider(incorrectCreds);
WebRequest request = new WebRequest(new URL(base + "/SecureServlet"), POST);
try {
webClient.getPage(request);
} catch (FailingHttpStatusCodeException e) {
assertNotNull(e);
assertEquals(401, e.getStatusCode());
return;
}
fail("/SecureServlet could be accessed without proper security credentials");
}
use of com.gargoylesoftware.htmlunit.WebRequest in project javaee7-samples by javaee-samples.
the class SecureServletTest method testPostWithCorrectCredentials.
@Test
public void testPostWithCorrectCredentials() throws Exception {
System.out.println("\n\n\nStarting testPostWithCorrectCredentials\n\n");
webClient.setCredentialsProvider(correctCreds);
WebRequest request = new WebRequest(new URL(base + "/SecureServlet"), POST);
TextPage page = webClient.getPage(request);
assertEquals("my POST", page.getContent());
}
use of com.gargoylesoftware.htmlunit.WebRequest in project promoted-builds-plugin by jenkinsci.
the class RemoteApiTest method getAndModify.
@Test
public void getAndModify() throws Exception {
FreeStyleProject p = r.createFreeStyleProject("p");
JobPropertyImpl promotion = new JobPropertyImpl(p);
p.addProperty(promotion);
PromotionProcess proc = promotion.addProcess("promo");
proc.conditions.add(new SelfPromotionCondition(true));
JenkinsRule.WebClient wc = r.createWebClient();
String xml = wc.goToXml("job/p/promotion/process/promo/config.xml").asXml().replaceAll("\\s*\\n\\s*", "");
assertTrue(xml, xml.contains("SelfPromotionCondition"));
assertTrue(xml, xml.contains("<evenIfUnstable>true</evenIfUnstable>"));
WebRequest req = new WebRequest(wc.createCrumbedUrl("job/p/promotion/process/promo/config.xml"), HttpMethod.POST);
req.setEncodingType(null);
req.setRequestBody(xml.replace("<evenIfUnstable>true</evenIfUnstable>", "<evenIfUnstable>false</evenIfUnstable>"));
assertTrue(proc.conditions.get(SelfPromotionCondition.class).isEvenIfUnstable());
wc.getPage(req);
assertFalse(proc.conditions.get(SelfPromotionCondition.class).isEvenIfUnstable());
}
use of com.gargoylesoftware.htmlunit.WebRequest in project promoted-builds-plugin by jenkinsci.
the class RemoteApiTest method create.
@Test
public void create() throws Exception {
FreeStyleProject p = r.createFreeStyleProject("p");
JobPropertyImpl promotion = new JobPropertyImpl(p);
p.addProperty(promotion);
assertEquals(0, promotion.getItems().size());
assertEquals(0, promotion.getActiveItems().size());
JenkinsRule.WebClient wc = r.createWebClient();
WebRequest req = new WebRequest(new URL(wc.createCrumbedUrl("job/p/promotion/createProcess") + "&name=promo"), HttpMethod.POST);
req.setEncodingType(null);
req.setRequestBody("<hudson.plugins.promoted__builds.PromotionProcess><conditions><hudson.plugins.promoted__builds.conditions.SelfPromotionCondition><evenIfUnstable>true</evenIfUnstable></hudson.plugins.promoted__builds.conditions.SelfPromotionCondition></conditions></hudson.plugins.promoted__builds.PromotionProcess>");
wc.getPage(req);
assertEquals(1, promotion.getItems().size());
assertEquals("not yet in use", 0, promotion.getActiveItems().size());
PromotionProcess proc = promotion.getItem("promo");
assertNotNull(proc);
assertTrue(proc.conditions.get(SelfPromotionCondition.class).isEvenIfUnstable());
}
Aggregations