Search in sources :

Example 81 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project spring-framework by spring-projects.

the class DelegatingWebConnectionTests method setup.

@BeforeEach
public void setup() throws Exception {
    request = new WebRequest(new URL("http://localhost/"));
    WebResponseData data = new WebResponseData("".getBytes("UTF-8"), 200, "", Collections.emptyList());
    expectedResponse = new WebResponse(data, request, 100L);
    webConnection = new DelegatingWebConnection(defaultConnection, new DelegateWebConnection(matcher1, connection1), new DelegateWebConnection(matcher2, connection2));
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) WebResponseData(com.gargoylesoftware.htmlunit.WebResponseData) DelegateWebConnection(org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection) URL(java.net.URL) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 82 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project promoted-builds-plugin by jenkinsci.

the class PromotionTest method testRebuildPromotionThrowsException.

@Test
public void testRebuildPromotionThrowsException() throws Exception {
    FreeStyleProject p = r.createFreeStyleProject("proj1");
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    PromotionProcess promo1 = promotion.addProcess("promo1");
    promo1.conditions.add(new SelfPromotionCondition(false));
    FreeStyleBuild b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
    // internally, the promotion is still an asynchronous process. It just happens
    // right away after the build is complete.
    Thread.sleep(1000);
    Promotion pb = promo1.getBuilds().getLastBuild();
    assertSame(pb.getTargetBuildOrFail(), b);
    JenkinsRule.WebClient wc = r.createWebClient();
    // spot-check that promotion itself is accessible
    wc.goTo(pb.getUrl());
    try {
        HtmlPage page = wc.getPage(wc.addCrumb(new WebRequest(new URL(r.getURL(), pb.getUrl() + "/rebuild"), HttpMethod.POST)));
        fail("rebuilding a promotion directly should fail");
    } catch (FailingHttpStatusCodeException x) {
        assertEquals("wrong status code", 404, x.getStatusCode());
    // TODO(oleg_nenashev): Another error will be returned since 2.107. As long as URL is rejected, we do not really care much
    // assertNotEquals("unexpected content", -1, x.getResponse().getContentAsString().indexOf("Promotions may not be rebuilt directly"));
    }
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) SelfPromotionCondition(hudson.plugins.promoted_builds.conditions.SelfPromotionCondition) FreeStyleBuild(hudson.model.FreeStyleBuild) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) FreeStyleProject(hudson.model.FreeStyleProject) URL(java.net.URL) Test(org.junit.Test)

Example 83 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project promoted-builds-plugin by jenkinsci.

the class RemoteApiTest method delete.

@Test
public void delete() throws Exception {
    FreeStyleProject p = r.createFreeStyleProject("p");
    JobPropertyImpl promotion = new JobPropertyImpl(p);
    p.addProperty(promotion);
    promotion.addProcess("promo").save();
    assertEquals(1, promotion.getItems().size());
    assertEquals(1, promotion.getActiveItems().size());
    JenkinsRule.WebClient wc = r.createWebClient();
    wc.getPage(wc.addCrumb(new WebRequest(new URL(r.getURL(), "job/p/promotion/process/promo/doDelete"), HttpMethod.POST)));
    assertEquals(0, promotion.getItems().size());
    assertEquals(0, promotion.getActiveItems().size());
}
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)

Example 84 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project support-core-plugin by jenkinsci.

the class SupportActionTest method doBundle.

private WebResponse doBundle(String action, String bundle, String user, String extraBundle) throws IOException {
    j.jenkins.setCrumbIssuer(null);
    j.jenkins.setSecurityRealm(j.createDummySecurityRealm());
    j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy().grant(Jenkins.ADMINISTER).everywhere().to("admin").grant(Jenkins.READ).everywhere().to("user"));
    WebClient wc = j.createWebClient().withBasicCredentials(user).withThrowExceptionOnFailingStatusCode(false);
    String json = "?json={%22bundles%22:[{%22selected%22:+true,%22name%22:+%22" + bundle + "%22}]}";
    if (extraBundle != null) {
        json = "?json={%22bundles%22:[{%22selected%22:+true,%22name%22:+%22" + bundle + "%22},{%22selected%22:+true,%22name%22:+%22" + extraBundle + "%22}]}";
    }
    WebRequest request = new WebRequest(new URL(j.getURL() + root.getUrlName() + "/" + action + json), HttpMethod.POST);
    return wc.getPage(request).getWebResponse();
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) MockAuthorizationStrategy(org.jvnet.hudson.test.MockAuthorizationStrategy) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.jvnet.hudson.test.JenkinsRule.WebClient) URL(java.net.URL)

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