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());
}
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);
}
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());
}
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));
}
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");
}
Aggregations