Search in sources :

Example 66 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project archiva by apache.

the class RepositoryServletNoProxyMetadataTest method testGetVersionMetadataDefaultLayout.

@Test
public void testGetVersionMetadataDefaultLayout() throws Exception {
    String commonsLangMetadata = "commons-lang/commons-lang/2.1/maven-metadata.xml";
    String expectedMetadataContents = "metadata-for-commons-lang-version-2.1";
    Path checksumFile = repoRootInternal.resolve(commonsLangMetadata);
    Files.createDirectories(checksumFile.getParent());
    org.apache.archiva.common.utils.FileUtils.writeStringToFile(checksumFile, Charset.defaultCharset(), expectedMetadataContents);
    WebRequest request = new GetMethodWebRequest("http://machine.com/repository/internal/" + commonsLangMetadata);
    WebResponse response = getServletUnitClient().getResponse(request);
    assertResponseOK(response);
    assertEquals("Expected file contents", expectedMetadataContents, response.getContentAsString());
}
Also used : Path(java.nio.file.Path) WebResponse(com.gargoylesoftware.htmlunit.WebResponse) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) Test(org.junit.Test)

Example 67 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project workflow-job-plugin by jenkinsci.

the class WorkflowJobTest method polling.

@Issue("JENKINS-34716")
@Test
public void polling() throws Exception {
    sampleRepo.init();
    sampleRepo.write("Jenkinsfile", "echo 'first version'");
    sampleRepo.git("add", "Jenkinsfile");
    sampleRepo.git("commit", "-m", "init");
    WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
    p.addTrigger(new SCMTrigger(""));
    p.setDefinition(new CpsScmFlowDefinition(new GitSCM(sampleRepo.toString()), "Jenkinsfile"));
    j.assertLogContains("first version", j.buildAndAssertSuccess(p));
    sampleRepo.write("Jenkinsfile", "echo 'second version'");
    sampleRepo.git("commit", "-a", "-m", "init");
    j.jenkins.setQuietPeriod(0);
    j.createWebClient().getPage(new WebRequest(j.createWebClient().createCrumbedUrl(p.getUrl() + "polling"), HttpMethod.POST));
    j.waitUntilNoActivity();
    WorkflowRun b2 = p.getLastBuild();
    assertEquals(2, b2.getNumber());
    j.assertLogContains("second version", b2);
}
Also used : SCMTrigger(hudson.triggers.SCMTrigger) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) CpsScmFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition) GitSCM(hudson.plugins.git.GitSCM) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 68 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project workflow-job-plugin by jenkinsci.

the class WorkflowJobTest method disabled.

@Issue("JENKINS-27299")
@Test
public void disabled() throws Exception {
    WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
    assertFalse(p.isDisabled());
    assertTrue(p.isBuildable());
    JenkinsRule.WebClient wc = j.createWebClient();
    j.submit(wc.getPage(p).<HtmlForm>getHtmlElementById("disable-project"));
    assertTrue(p.isDisabled());
    assertFalse(p.isBuildable());
    HtmlForm form = wc.getPage(p, "configure").getFormByName("config");
    HtmlCheckBoxInput checkbox = form.getInputByName("disable");
    assertTrue(checkbox.isChecked());
    checkbox.setChecked(false);
    j.submit(form);
    assertFalse(p.isDisabled());
    wc.getPage(new WebRequest(wc.createCrumbedUrl(p.getUrl() + "disable"), HttpMethod.POST));
    assertTrue(p.isDisabled());
    assertNull(p.scheduleBuild2(0));
    assertThat(new CLICommandInvoker(j, "enable-job").invokeWithArgs("p"), CLICommandInvoker.Matcher.succeededSilently());
    assertFalse(p.isDisabled());
}
Also used : HtmlCheckBoxInput(com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput) HtmlForm(com.gargoylesoftware.htmlunit.html.HtmlForm) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) CLICommandInvoker(hudson.cli.CLICommandInvoker) Issue(org.jvnet.hudson.test.Issue) Test(org.junit.Test)

Example 69 with WebRequest

use of com.gargoylesoftware.htmlunit.WebRequest in project javaee7-samples by javaee-samples.

the class SecureServletTest method testPostMethod.

@Test
public void testPostMethod() throws Exception {
    webClient.setCredentialsProvider(correctCreds);
    WebRequest request = new WebRequest(new URL(base + "SecureServlet"), POST);
    TextPage p = null;
    try {
        p = webClient.getPage(request);
        System.out.println(p.getContent());
        assertFalse("POST method could be called even with deny-uncovered-http-methods", p.getContent().contains("my POST"));
    } catch (FailingHttpStatusCodeException e) {
        assertNotNull(e);
        assertEquals(403, e.getStatusCode());
        return;
    }
    fail("POST correctly not called, but wrong status code: " + (p != null ? p.getWebResponse().getStatusCode() : -1));
}
Also used : WebRequest(com.gargoylesoftware.htmlunit.WebRequest) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) TextPage(com.gargoylesoftware.htmlunit.TextPage) URL(java.net.URL) Test(org.junit.Test)

Example 70 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 {
    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)

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