本文整理汇总了Java中org.jvnet.hudson.test.JenkinsRule.WebClient方法的典型用法代码示例。如果您正苦于以下问题:Java JenkinsRule.WebClient方法的具体用法?Java JenkinsRule.WebClient怎么用?Java JenkinsRule.WebClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jvnet.hudson.test.JenkinsRule
的用法示例。
在下文中一共展示了JenkinsRule.WebClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticatedAccess
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
/**
*
* @throws Exception
*/
@PresetData(NO_ANONYMOUS_READACCESS)
@Test
public void authenticatedAccess() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject("free");
JenkinsRule.WebClient wc = j.createWebClient();
wc.login("alice", "alice");
try {
// try with wrong job name
wc.goTo("buildStatus/buildIcon?job=dummy");
fail("should fail, because there is no job with this name");
} catch (FailingHttpStatusCodeException x) {
assertEquals(HTTP_NOT_FOUND, x.getStatusCode());
}
wc.goTo("buildStatus/buildIcon?job=free", "image/svg+xml");
j.buildAndAssertSuccess(project);
}
示例2: validAnonymousViewStatusAccess
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
/**
*
* @throws Exception
*/
@Test
public void validAnonymousViewStatusAccess() throws Exception {
final SecurityRealm realm = j.createDummySecurityRealm();
j.jenkins.setSecurityRealm(realm);
GlobalMatrixAuthorizationStrategy auth = new GlobalMatrixAuthorizationStrategy();
auth.add(VIEW_STATUS, "anonymous");
j.getInstance().setSecurityRealm(realm);
j.getInstance().setAuthorizationStrategy(auth);
final FreeStyleProject project = j.createFreeStyleProject("free");
JenkinsRule.WebClient wc = j.createWebClient();
try {
// try with wrong job name
wc.goTo("buildStatus/buildIcon?job=dummy");
fail("should fail, because there is no job with this name");
} catch (FailingHttpStatusCodeException x) {
assertEquals(HTTP_NOT_FOUND, x.getStatusCode());
}
wc.goTo("buildStatus/buildIcon?job=free", "image/svg+xml");
j.buildAndAssertSuccess(project);
}
示例3: validAnonymousAccess
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
/**
*
* @throws Exception
*/
@PresetData(ANONYMOUS_READONLY)
@Test
public void validAnonymousAccess() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject("free");
JenkinsRule.WebClient wc = j.createWebClient();
try {
// try with wrong job name
wc.goTo("buildStatus/buildIcon?job=dummy");
fail("should fail, because there is no job with this name");
} catch (FailingHttpStatusCodeException x) {
assertEquals(HTTP_NOT_FOUND, x.getStatusCode());
}
// try with correct job name
wc.goTo("buildStatus/buildIcon?job=free", "image/svg+xml");
j.buildAndAssertSuccess(project);
}
示例4: showProblems
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
@Test
public void showProblems() throws Exception {
disposer = AsyncResourceDisposer.get();
disposer.dispose(new FailingDisposable());
Thread.sleep(1000);
JenkinsRule.WebClient wc = j.createWebClient();
assertFalse(disposer.isActivated());
HtmlPage manage = wc.goTo("manage");
assertThat(manage.asText(), not(containsString("There are resources Jenkins was not able to dispose automatically")));
Whitebox.setInternalState(disposer.getBacklog().iterator().next(), "registered", new Date(0)); // Make it decades old
assertTrue(disposer.isActivated());
manage = wc.goTo("manage");
assertThat(manage.asText(), containsString("There are resources Jenkins was not able to dispose automatically"));
HtmlPage report = wc.goTo(disposer.getUrl());
assertThat(report.asText(), containsString("Failing disposable"));
assertThat(report.asText(), containsString("IOException: Unable to dispose"));
}
示例5: shouldCreatePipelineAndViewAndSuccessfullyBuildDefinition
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
private void shouldCreatePipelineAndViewAndSuccessfullyBuildDefinition(String script) throws Exception {
String projectName = "TaskPipeline";
WorkflowJob pipeline = jenkins.getInstance().createProject(WorkflowJob.class, projectName);
pipeline.setDefinition(new CpsFlowDefinition(script, true));
pipeline.scheduleBuild(0, new BuildCommand.CLICause());
jenkins.waitUntilNoActivity();
assertThat(pipeline.getLastBuild().getResult(), is(Result.SUCCESS));
String viewName = "TaskPipelineView";
WorkflowPipelineView view = new WorkflowPipelineView(viewName);
view.setProject(projectName);
jenkins.getInstance().addView(view);
JenkinsRule.WebClient client = jenkins.createWebClient();
Page viewPage = client.getPage(new URL(jenkins.getURL(), "/jenkins/view/" + viewName));
assertThat(viewPage.getWebResponse().getStatusCode(), is(200));
Page apiPage = client.getPage(new URL(jenkins.getURL(), "/jenkins/view/" + viewName + "/api/json"));
assertThat(apiPage.getWebResponse().getStatusCode(), is(200));
}
示例6: shouldNotSeeMigrationButton
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
@Test
public void shouldNotSeeMigrationButton() throws IOException, SAXException {
JenkinsRule.WebClient webClient = jenkinsRule.createWebClient();
DomElement configureSection = webClient.goTo("configure").getElementsByName("AwsCodeCommitTriggerPlugin").get(0);
List<?> buttons = configureSection.getByXPath("//button[contains(.,'Migration')]");
Assertions.assertThat(buttons).isEmpty();
}
示例7: showWhenCloudsConfigured
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
@Test
public void showWhenCloudsConfigured() throws Exception {
JenkinsRule.WebClient webClient = j.createWebClient();
String content = webClient.goTo("").getWebResponse().getContentAsString();
assertThat(content, not(containsString("Cloud Statistics")));
assertThat(content, not(containsString("#cloudstats")));
j.jenkins.clouds.add(new TestCloud("asdf"));
content = webClient.goTo("").getWebResponse().getContentAsString();
assertThat(content, containsString("Cloud Statistics"));
assertThat(content, containsString("#cloudstats"));
}
示例8: doNotShowWhenNotAuthenticated
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
@Test @PresetData(PresetData.DataSet.ANONYMOUS_READONLY)
public void doNotShowWhenNotAuthenticated() throws Exception {
j.jenkins.clouds.add(new TestCloud("asdf"));
JenkinsRule.WebClient webClient = j.createWebClient();
String content = webClient.goTo("").getWebResponse().getContentAsString();
assertThat(content, not(containsString("Cloud Statistics")));
assertThat(content, not(containsString("#cloudstats")));
}
示例9: testFingerprintUi
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
@Test
@LocalData
public void testFingerprintUi() throws IOException, InterruptedException, SAXException {
JenkinsRule.WebClient web = j.createWebClient();
HtmlPage page = web.goTo("dockerhub-webhook/details/e9d6eb6cd6a7bfcd2bd622765a87893f");
j.assertStringContains(page.asText(), "Build results for push of csanchez/jenkins-swarm-slave");
}
示例10: rawContainerDockerInspectSubmissions
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
@Test
public void rawContainerDockerInspectSubmissions() throws Exception {
// Read data from resources
String inspectData = JSONSamples.inspectContainerData.readString();
InspectContainerResponse inspectResponse = JSONSamples.inspectContainerData.
readObject(InspectContainerResponse[].class)[0];
final String containerId = inspectResponse.getId();
final String imageId = inspectResponse.getImageId();
// Init system data
JenkinsRule.WebClient client = j.createWebClient();
final DockerTraceabilityRootAction action = DockerTraceabilityRootAction.getInstance();
assertNotNull(action);
// Prepare a run with Fingerprints and referenced facets
createTestBuildRefFacet(imageId, "test");
// Submit JSON
action.doSubmitContainerStatus(inspectData, null, null, null, 0, null, null);
// Ensure there's a fingerprint for container, which refers the image
final DockerDeploymentFacet containerFacet = assertExistsDeploymentFacet(containerId, imageId);
// Ensure there's a fingerprint for image
final DockerDeploymentRefFacet containerRefFacet = assertExistsDeploymentRefFacet(containerId, imageId);
// Try to call the actions method to retrieve the data
final Page res;
try {
res = client.goTo("docker-traceability/rawContainerInfo?id="+containerId, null);
} catch (Exception ex) {
ex.getMessage();
throw new AssertionError("Cannot get a response from rawInfo page", ex);
}
final String responseJSON = res.getWebResponse().getContentAsString();
ObjectMapper mapper= new ObjectMapper();
final InspectContainerResponse[] parsedData = mapper.readValue(responseJSON, InspectContainerResponse[].class);
assertEquals(1, parsedData.length);
}
示例11: containerIDs_CRUD
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
@Test
public void containerIDs_CRUD() throws Exception {
// TODO: replace by a helper method from the branch
JenkinsRule.WebClient client = j.createWebClient();
@CheckForNull DockerTraceabilityRootAction action = null;
for (Action rootAction : j.getInstance().getActions()) {
if (rootAction instanceof DockerTraceabilityRootAction) {
action = (DockerTraceabilityRootAction) rootAction;
break;
}
}
assertNotNull(action);
final String id1 = FingerprintTestUtil.generateDockerId("1");
final String id2 = FingerprintTestUtil.generateDockerId("2");
final String id3 = FingerprintTestUtil.generateDockerId("3");
// Check consistency of create/update commands
action.addContainerID(id1);
assertEquals(1, action.getContainerIDs().size());
action.addContainerID(id2);
assertEquals(2, action.getContainerIDs().size());
action.addContainerID(id2);
assertEquals(2, action.getContainerIDs().size());
// Remove data using API. First entry is non-existent
action.doDeleteContainer(id3);
assertEquals(2, action.getContainerIDs().size());
action.doDeleteContainer(id1);
assertEquals(1, action.getContainerIDs().size());
action.doDeleteContainer(id1);
assertEquals(1, action.getContainerIDs().size());
// Reload the data and ensure the status has been persisted correctly
action = new DockerTraceabilityRootAction();
assertEquals(1, action.getContainerIDs().size());
for (String id : action.getContainerIDs()) {
assertEquals(id2, id);
}
}
示例12: verifyUsernameInflightRequest
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
@Test
@Bug(24671)
public void verifyUsernameInflightRequest() throws Exception {
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
JenkinsRule.WebClient webClient = r.createWebClient().login("bob", "bob");
MockSlowURLCall.seconds = 5;
webClient.goTo("mockSlowURLCall/submit");
InflightRequest request = MockSlowURLCall.request;
assertNotNull(request);
assertEquals("bob", request.userName);
assertEquals(webClient.getContextPath() + "mockSlowURLCall/submit", request.url);
}
示例13: verifyRefererHeaderFromInflightRequest
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
@Test
@Bug(24671)
public void verifyRefererHeaderFromInflightRequest() throws Exception {
JenkinsRule.WebClient webClient = r.createWebClient();
URL refererUrl = new URL(webClient.getContextPath() + "mockSlowURLCall/submitReferer");
((HtmlPage) webClient.getPage(refererUrl)).getHtmlElementById("link").click();
InflightRequest request = MockSlowURLCall.request;
assertEquals(refererUrl.toString(), request.referer);
}
示例14: ui
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
@Test
public void ui() throws Exception {
j.jenkins.clouds.add(new TestCloud("MyCloud"));
j.jenkins.clouds.add(new TestCloud("PickyCloud"));
String message = "Something bad happened. Something bad happened. Something bad happened. Something bad happened. Something bad happened. Something bad happened.";
CloudStatistics cs = CloudStatistics.get();
CloudStatistics.ProvisioningListener provisioningListener = CloudStatistics.ProvisioningListener.get();
// When
ProvisioningActivity.Id provisionId = new ProvisioningActivity.Id("MyCloud", "broken-template");
provisioningListener.onStarted(provisionId);
provisioningListener.onFailure(provisionId, new Exception(message));
ProvisioningActivity.Id warnId = new ProvisioningActivity.Id("PickyCloud", null, "slave");
provisioningListener.onStarted(warnId);
Node slave = createTrackedSlave(warnId, j);
ProvisioningActivity a = provisioningListener.onComplete(warnId, slave);
a.attach(LAUNCHING, new PhaseExecutionAttachment(WARN, "There is something attention worthy"));
slave.toComputer().waitUntilOnline();
ProvisioningActivity.Id okId = new ProvisioningActivity.Id("MyCloud", "working-template", "future-slave");
provisioningListener.onStarted(okId);
slave = createTrackedSlave(okId, j);
provisioningListener.onComplete(okId, slave);
slave.toComputer().waitUntilOnline();
Thread.sleep(500);
slave.toComputer().doDoDelete();
detectCompletionNow(); // Force completion detection
Thread.sleep(500);
// Then
List<ProvisioningActivity> all = cs.getActivities();
ProvisioningActivity failedToProvision = all.get(0);
assertEquals(provisionId, failedToProvision.getId());
assertEquals(FAIL, failedToProvision.getStatus());
assertEquals(null, failedToProvision.getPhaseExecution(LAUNCHING));
assertEquals(null, failedToProvision.getPhaseExecution(OPERATING));
assertNotNull(failedToProvision.getPhaseExecution(COMPLETED));
PhaseExecution failedProvisioning = failedToProvision.getPhaseExecution(PROVISIONING);
assertEquals(FAIL, failedProvisioning.getStatus());
PhaseExecutionAttachment.ExceptionAttachment exception = (PhaseExecutionAttachment.ExceptionAttachment) failedProvisioning.getAttachments().get(0);
assertEquals(message, exception.getTitle());
assertThat(exception.getText(), startsWith("java.lang.Exception: " + message));
JenkinsRule.WebClient wc = j.createWebClient();
j.jenkins.setAuthorizationStrategy(AuthorizationStrategy.UNSECURED);
Page page = wc.goTo("cloud-stats").getAnchorByHref(j.jenkins.getRootUrl() + cs.getUrl(failedToProvision, failedProvisioning, exception)).click();
assertThat(page.getWebResponse().getContentAsString(), containsString(message));
ProvisioningActivity ok = all.get(1);
assertEquals(okId, ok.getId());
assertEquals(OK, ok.getStatus());
assertNotNull(ok.getPhaseExecution(PROVISIONING));
assertNotNull(ok.getPhaseExecution(LAUNCHING));
assertNotNull(ok.getPhaseExecution(OPERATING));
assertNotNull(ok.getPhaseExecution(COMPLETED));
ProvisioningActivity warn = all.get(2);
assertEquals(warnId, warn.getId());
assertEquals(WARN, warn.getStatus());
assertNotNull(warn.getPhaseExecution(PROVISIONING));
assertNotNull(warn.getPhaseExecution(LAUNCHING));
assertNotNull(warn.getPhaseExecution(OPERATING));
assertNull(warn.getPhaseExecution(COMPLETED));
PhaseExecution warnedLaunch = warn.getPhaseExecution(LAUNCHING);
assertEquals(WARN, warnedLaunch.getStatus());
assertEquals("There is something attention worthy", warnedLaunch.getAttachments().get(0).getTitle());
assertEquals(CloudStatistics.get().getIndex().cloudHealth("MyCloud").getOverall().getPercentage(), 50D, 0);
assertEquals(CloudStatistics.get().getIndex().cloudHealth("PickyCloud").getOverall().getPercentage(), 100D, 0);
//j.interactiveBreak();
}
示例15: submitEvent
import org.jvnet.hudson.test.JenkinsRule; //导入方法依赖的package包/类
/**
* Checks {@link DockerEventsAction#doSubmitEvent(org.kohsuke.stapler.StaplerRequest,
* org.kohsuke.stapler.StaplerResponse, java.lang.String) }
* @throws Exception test failure
*/
@Test
public void submitEvent() throws Exception {
// Read data from resources
String reportString = JSONSamples.submitReport.readString();
DockerTraceabilityReport report = JSONSamples.submitReport.
readObject(DockerTraceabilityReport.class);
final String containerId = report.getContainer().getId();
final String imageId = report.getImageId();
// Init system data
// TODO: replace by a helper method from the branch
JenkinsRule.WebClient client = j.createWebClient();
@CheckForNull DockerTraceabilityRootAction action = null;
for (Action rootAction : j.getInstance().getActions()) {
if (rootAction instanceof DockerTraceabilityRootAction) {
action = (DockerTraceabilityRootAction) rootAction;
break;
}
}
assertNotNull(action);
// Prepare a run with Fingerprints and referenced facets
createTestBuildRefFacet(imageId, "test");
// Submit JSON
action.doSubmitReport(reportString);
// Ensure there's are expected fingerprints
final DockerDeploymentFacet containerFacet = assertExistsDeploymentFacet(containerId, imageId);
final DockerDeploymentRefFacet containerRefFacet = assertExistsDeploymentRefFacet(containerId, imageId);
final DockerInspectImageFacet inspectImageFacet = assertExistsInspectImageFacet(imageId);
// Try to call the actions method to retrieve the data
final Page res;
try {
res = client.goTo("docker-traceability/rawImageInfo?id="+imageId, null);
} catch (Exception ex) {
ex.getMessage();
throw new AssertionError("Cannot get a response from rawInfo page", ex);
}
final String responseJSON = res.getWebResponse().getContentAsString();
ObjectMapper mapper= new ObjectMapper();
final InspectImageResponse[] parsedData = mapper.readValue(responseJSON, InspectImageResponse[].class);
assertEquals(1, parsedData.length);
InspectImageResponse apiResponse = parsedData[0];
assertEquals(imageId, apiResponse.getId());
}