本文整理匯總了Java中org.jvnet.hudson.test.JenkinsRule類的典型用法代碼示例。如果您正苦於以下問題:Java JenkinsRule類的具體用法?Java JenkinsRule怎麽用?Java JenkinsRule使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JenkinsRule類屬於org.jvnet.hudson.test包,在下文中一共展示了JenkinsRule類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: smokes
import org.jvnet.hudson.test.JenkinsRule; //導入依賴的package包/類
@Test public void smokes() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("echo 'hello there'", true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
List<LogAction> logActions = new ArrayList<LogAction>();
for (FlowNode n : new FlowGraphWalker(b.getExecution())) {
LogAction la = n.getAction(LogAction.class);
if (la != null) {
logActions.add(la);
}
}
assertEquals(1, logActions.size());
StringWriter w = new StringWriter();
logActions.get(0).getLogText().writeLogTo(0, w);
assertEquals("hello there", w.toString().trim());
Matcher m = Pattern.compile("hello there").matcher(JenkinsRule.getLog(b));
assertTrue("message printed once", m.find());
assertFalse("message not printed twice", m.find());
}
示例2: 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);
}
示例3: toolWithoutSymbol
import org.jvnet.hudson.test.JenkinsRule; //導入依賴的package包/類
@Test public void toolWithoutSymbol() throws Exception {
File toolHome = folder.newFolder("mockTools");
MockToolWithoutSymbol tool = new MockToolWithoutSymbol("mock-tool-without-symbol", toolHome.getAbsolutePath(), JenkinsRule.NO_PROPERTIES);
Jenkins.getInstance().getDescriptorByType(MockToolWithoutSymbol.MockToolWithoutSymbolDescriptor.class).setInstallations(tool);
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {def home = tool name: '" + tool.getName() + "', type: 'mockToolWithoutSymbol'}",
true));
r.assertLogContains("No mockToolWithoutSymbol named mock-tool-without-symbol found",
r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0)));
p.setDefinition(new CpsFlowDefinition("node {def home = tool name: '" + tool.getName() + "', type: '" + MockToolWithoutSymbol.class.getName() + "'\n"
+ "echo \"${home}\"}",
true));
r.assertLogContains(toolHome.getAbsolutePath(),
r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
示例4: 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);
}
示例5: 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);
}
示例6: allowedGroup
import org.jvnet.hudson.test.JenkinsRule; //導入依賴的package包/類
@Test
public void allowedGroup() throws Exception {
String username = "foobar";
String group = "allowed";
GroupSelector groupSelector = new GroupSelector(group);
JobRestriction restriction = new StartedByMemberOfGroupRestriction(singletonList(groupSelector), false);
setUpDiskPoolRestriction(restriction);
JenkinsRule.DummySecurityRealm securityRealm = j.createDummySecurityRealm();
securityRealm.addGroups(username, group);
j.jenkins.setSecurityRealm(securityRealm);
authenticate(username);
WorkflowRun run = createWorkflowJobAndRun();
j.assertBuildStatusSuccess(run);
j.assertLogContains(format("Selected Disk ID '%s' from the Disk Pool ID '%s'", DISK_ID_ONE, DISK_POOL_ID), run);
}
示例7: notAllowedGroup
import org.jvnet.hudson.test.JenkinsRule; //導入依賴的package包/類
@Test
public void notAllowedGroup() throws Exception {
String username = "foobar";
String group = "allowed";
GroupSelector groupSelector = new GroupSelector("not-allowed-group");
JobRestriction restriction = new StartedByMemberOfGroupRestriction(singletonList(groupSelector), false);
setUpDiskPoolRestriction(restriction);
JenkinsRule.DummySecurityRealm securityRealm = j.createDummySecurityRealm();
securityRealm.addGroups(username, group);
j.jenkins.setSecurityRealm(securityRealm);
authenticate(username);
WorkflowRun run = createWorkflowJobAndRun();
j.assertBuildStatus(Result.FAILURE, run);
j.assertLogContains(format("Disk Pool identified by '%s' is not accessible due to the applied Disk Pool restriction: Started By member of group", DISK_POOL_ID), run);
}
示例8: sharedWorkspaceBetweenTwoDifferentNodes
import org.jvnet.hudson.test.JenkinsRule; //導入依賴的package包/類
@Test
public void sharedWorkspaceBetweenTwoDifferentNodes() throws Exception {
addExternalWorkspaceNodeProperty(node1, DISK_POOL_ID, nodeDisk1, nodeDisk2);
addExternalWorkspaceNodeProperty(node2, DISK_POOL_ID, nodeDisk1, nodeDisk2);
WorkflowJob jobWithTwoNodes = createWorkflowJobWithTwoNodes();
runWorkflowJob(jobWithTwoNodes);
Disk allocatedDisk = findAllocatedDisk(disk1, disk2);
j.assertBuildStatusSuccess(run);
j.assertLogContains("Searching for disk definitions in the External Workspace Templates from Jenkins global config", run);
j.assertLogContains("Searching for disk definitions in the Node config", run);
j.assertLogContains(format("Running in %s/%s/%s/%d",
allocatedDisk.getMasterMountPoint(), allocatedDisk.getPhysicalPathOnDisk(), run.getParent().getName(), run.getNumber()), run);
// The text written to file should be printed twice on the console output (when writing and when reading the file)
assertThat(countMatches(JenkinsRule.getLog(run), TEXT), is(2));
}
示例9: sharedWorkspaceBetweenTwoDifferentNodesWithTemplate
import org.jvnet.hudson.test.JenkinsRule; //導入依賴的package包/類
@Test
public void sharedWorkspaceBetweenTwoDifferentNodesWithTemplate() throws Exception {
NodeDiskPool nodeDiskPool = new NodeDiskPool(DISK_POOL_ID, Arrays.asList(nodeDisk1, nodeDisk2));
Template linuxTemplate = new Template("linux", Collections.singletonList(nodeDiskPool));
Template testTemplate = new Template("test", Collections.singletonList(nodeDiskPool));
setUpTemplates(linuxTemplate, testTemplate);
WorkflowJob jobWithTwoNodes = createWorkflowJobWithTwoNodes();
runWorkflowJob(jobWithTwoNodes);
Disk allocatedDisk = findAllocatedDisk(disk1, disk2);
j.assertBuildStatusSuccess(run);
j.assertLogContains("Searching for disk definitions in the External Workspace Templates from Jenkins global config", run);
j.assertLogNotContains("Searching for disk definitions in the Node config", run);
j.assertLogContains(format("Running in %s/%s/%s/%d",
allocatedDisk.getMasterMountPoint(), allocatedDisk.getPhysicalPathOnDisk(), run.getParent().getName(), run.getNumber()), run);
// The text written to file should be printed twice on the console output (when writing and when reading the file)
assertThat(countMatches(JenkinsRule.getLog(run), TEXT), is(2));
}
示例10: migrateDataTest
import org.jvnet.hudson.test.JenkinsRule; //導入依賴的package包/類
/**
* Utility to aid in performing a round trip migration test on a <code>CpwrScmConfiguration</code> configuration.
* <p>
* An existing project is loaded, migrated, saved, and reloaded where the original configuration is compared against
* the reloaded configuration. The test project is loaded from a .zip file that mimics a Jenkins project's
* layout within.
*
* See test resource for the migration test: src/test/resources/com.compuware.jenkins.scm/<test>/<test method>.zip
*
* @param jenkinsRule
* the Jenkins rule
*/
public static void migrateDataTest(JenkinsRule jenkinsRule)
{
try
{
// Load and migrate the specified project from the test resource .zip file
TopLevelItem item = jenkinsRule.jenkins.getItem("TestProject");
assertDataMigrated(item);
}
catch (Exception e)
{
// Add the print of the stack trace because the exception message is not enough to troubleshoot the root issue. For
// example, if the exception is constructed without a message, you get no information from executing fail().
e.printStackTrace();
fail(e.getMessage());
}
}
示例11: 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"));
}
示例12: givenSearchWhenJobsWithBuildsAreExecutedThenTheyShouldBeSearchable
import org.jvnet.hudson.test.JenkinsRule; //導入依賴的package包/類
public static void givenSearchWhenJobsWithBuildsAreExecutedThenTheyShouldBeSearchable(
JenkinsSearchBackend jenkinsSearchBackend, JenkinsRule rule) throws IOException, ExecutionException,
InterruptedException, SAXException, URISyntaxException, TimeoutException {
assertEquals(0, jenkinsSearchBackend.search("echo").suggestions.size());
FreeStyleProject project1 = rule.createFreeStyleProject("project1");
project1.getBuildersList().add(new Shell("echo $BUILD_TAG\n"));
// Building
project1.scheduleBuild2(0).get();
project1.scheduleBuild2(0).get();
project1.scheduleBuild2(0).get();
rule.createFreeStyleProject("project2");
FreeStyleProject project3 = rule.createFreeStyleProject("project3");
project3.getBuildersList().add(new Shell("cat $BUILD_TAG\n"));
assertEquals(3, jenkinsSearchBackend.search("echo").suggestions.size());
rebuildDatabase(jenkinsSearchBackend, rule);
assertEquals(3, jenkinsSearchBackend.search("echo").suggestions.size());
}
示例13: givenSearchWhenIsNewItShouldSupportRebuildFromClean
import org.jvnet.hudson.test.JenkinsRule; //導入依賴的package包/類
public static void givenSearchWhenIsNewItShouldSupportRebuildFromClean(JenkinsSearchBackend jenkinsSearchBackend,
JenkinsRule rule) throws IOException, ExecutionException, InterruptedException, SAXException,
URISyntaxException {
try {
assertEquals(0, jenkinsSearchBackend.search("echo").suggestions.size());
rebuildDatabase(jenkinsSearchBackend, rule);
assertEquals(0, jenkinsSearchBackend.search("echo").suggestions.size());
FreeStyleProject project1 = rule.createFreeStyleProject("project1");
project1.getBuildersList().add(new Shell("echo $BUILD_TAG\n"));
// Building
project1.scheduleBuild2(0).get();
project1.scheduleBuild2(0).get();
project1.scheduleBuild2(0).get();
rebuildDatabase(jenkinsSearchBackend, rule);
assertEquals(3, jenkinsSearchBackend.search("echo").suggestions.size());
} catch (Exception e) {
throw new AssertionError(e);
}
}
示例14: configurePretestedIntegrationPlugin
import org.jvnet.hudson.test.JenkinsRule; //導入依賴的package包/類
public static FreeStyleProject configurePretestedIntegrationPlugin(JenkinsRule rule, STRATEGY_TYPE type, List<UserRemoteConfig> repoList, String repoName, boolean runOnSlave, String integrationBranch) throws Exception {
FreeStyleProject project = rule.createFreeStyleProject();
if (runOnSlave) {
DumbSlave onlineSlave = rule.createOnlineSlave();
project.setAssignedNode(onlineSlave);
}
List<GitSCMExtension> gitSCMExtensions = new ArrayList<>();
gitSCMExtensions.add(new PretestedIntegrationAsGitPluginExt(type == STRATEGY_TYPE.SQUASH ? new SquashCommitStrategy() : new AccumulatedCommitStrategy(), integrationBranch, repoName));
gitSCMExtensions.add(new PruneStaleBranch());
gitSCMExtensions.add(new CleanCheckout());
project.getPublishersList().add(new PretestedIntegrationPostCheckout());
GitSCM gitSCM = new GitSCM(repoList,
Collections.singletonList(new BranchSpec("*/ready/**")),
false, Collections.<SubmoduleConfig>emptyList(),
null, null, gitSCMExtensions);
project.setScm(gitSCM);
project.save();
return project;
}
示例15: 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));
}