Search in sources :

Example 26 with WebRequest

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());
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) TextPage(com.gargoylesoftware.htmlunit.TextPage) URL(java.net.URL) Test(org.junit.Test)

Example 27 with WebRequest

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");
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) URL(java.net.URL) Test(org.junit.Test)

Example 28 with WebRequest

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());
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) TextPage(com.gargoylesoftware.htmlunit.TextPage) URL(java.net.URL) Test(org.junit.Test)

Example 29 with WebRequest

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());
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 30 with WebRequest

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());
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) URL(java.net.URL) Test(org.junit.Test)

Aggregations

WebRequest (com.gargoylesoftware.htmlunit.WebRequest)84 Test (org.junit.Test)65 WebResponse (com.gargoylesoftware.htmlunit.WebResponse)49 URL (java.net.URL)31 Path (java.nio.file.Path)31 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)12 TextPage (com.gargoylesoftware.htmlunit.TextPage)12 InputStream (java.io.InputStream)7 MkColMethodWebRequest (org.apache.archiva.webdav.httpunit.MkColMethodWebRequest)7 JenkinsRule (org.jvnet.hudson.test.JenkinsRule)7 WebClient (com.gargoylesoftware.htmlunit.WebClient)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)5 IOException (java.io.IOException)5 FreeStyleProject (hudson.model.FreeStyleProject)4 Page (com.gargoylesoftware.htmlunit.Page)3 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)3 HashMap (java.util.HashMap)3 Issue (org.jvnet.hudson.test.Issue)3 SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)2 IncorrectnessListener (com.gargoylesoftware.htmlunit.IncorrectnessListener)2