This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-31202] Updating pom for new test.
- Loading branch information
1 parent
4f19b3f
commit 4321730
Showing
2 changed files
with
197 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/test/java/hudson/plugins/warnings/WarningsWorkflowMultiBranchTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2015 CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package hudson.plugins.warnings; | ||
|
||
import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject; | ||
|
||
import com.cloudbees.hudson.plugins.folder.computed.FolderComputation; | ||
import hudson.model.Item; | ||
import hudson.plugins.git.GitSCM; | ||
import hudson.scm.SCM; | ||
import hudson.scm.SCMDescriptor; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import javax.annotation.Nonnull; | ||
import jenkins.branch.BranchProperty; | ||
import jenkins.branch.BranchPropertyDescriptor; | ||
import jenkins.branch.BranchPropertyStrategy; | ||
import jenkins.branch.BranchPropertyStrategyDescriptor; | ||
import jenkins.branch.BranchSource; | ||
import jenkins.branch.DefaultBranchPropertyStrategy; | ||
import jenkins.branch.NamedExceptionsBranchPropertyStrategy; | ||
import jenkins.plugins.git.GitSCMSource; | ||
import jenkins.plugins.git.GitSampleRepoRule; | ||
import jenkins.scm.api.SCMHead; | ||
import jenkins.scm.api.SCMSource; | ||
import jenkins.scm.impl.SingleSCMSource; | ||
import static org.hamcrest.Matchers.*; | ||
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
import static org.junit.Assert.*; | ||
import org.junit.ClassRule; | ||
import org.junit.Ignore; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.TestExtension; | ||
|
||
public class WarningsWorkflowMultiBranchTest { | ||
|
||
@Rule public JenkinsRule r = new JenkinsRule(); | ||
@Rule public GitSampleRepoRule sampleRepo = new GitSampleRepoRule(); | ||
|
||
@Test public void basicBranches() throws Exception { | ||
sampleRepo.init(); | ||
sampleRepo.write("Jenkinsfile", "echo \"branch=${env.BRANCH_NAME}\"; node {checkout scm; echo readFile('file')}"); | ||
sampleRepo.write("file", "initial content"); | ||
sampleRepo.git("add", "Jenkinsfile"); | ||
sampleRepo.git("commit", "--all", "--message=flow"); | ||
WorkflowMultiBranchProject mp = r.jenkins.createProject(WorkflowMultiBranchProject.class, "p"); | ||
mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", false), new DefaultBranchPropertyStrategy(new BranchProperty[0]))); | ||
WorkflowJob p = scheduleAndFindBranchProject(mp, "master"); | ||
assertEquals(new SCMHead("master"), SCMHead.HeadByItem.findHead(p)); | ||
assertEquals(1, mp.getItems().size()); | ||
r.waitUntilNoActivity(); | ||
WorkflowRun b1 = p.getLastBuild(); | ||
assertEquals(1, b1.getNumber()); | ||
sampleRepo.git("checkout", "-b", "feature"); | ||
sampleRepo.write("Jenkinsfile", "echo \"branch=${env.BRANCH_NAME}\"; node {checkout scm; echo readFile('file').toUpperCase()}"); | ||
ScriptApproval.get().approveSignature("method java.lang.String toUpperCase"); | ||
sampleRepo.write("file", "subsequent content"); | ||
sampleRepo.git("commit", "--all", "--message=tweaked"); | ||
p = scheduleAndFindBranchProject(mp, "feature"); | ||
assertEquals(2, mp.getItems().size()); | ||
r.waitUntilNoActivity(); | ||
b1 = p.getLastBuild(); | ||
assertEquals(1, b1.getNumber()); | ||
} | ||
|
||
// TODO commit notifications can both add branch projects and build them | ||
// TODO scheduled reindexing can add branch projects | ||
// TODO regular polling works on branch projects | ||
// TODO changelog shows per-branch changes | ||
|
||
public static @Nonnull WorkflowJob scheduleAndFindBranchProject(@Nonnull WorkflowMultiBranchProject mp, @Nonnull String name) throws Exception { | ||
mp.scheduleBuild2(0).getFuture().get(); | ||
return findBranchProject(mp, name); | ||
} | ||
|
||
public static @Nonnull WorkflowJob findBranchProject(@Nonnull WorkflowMultiBranchProject mp, @Nonnull String name) throws Exception { | ||
WorkflowJob p = mp.getItem(name); | ||
showIndexing(mp); | ||
if (p == null) { | ||
fail(name + " project not found"); | ||
} | ||
return p; | ||
} | ||
|
||
static void showIndexing(@Nonnull WorkflowMultiBranchProject mp) throws Exception { | ||
FolderComputation<?> indexing = mp.getIndexing(); | ||
System.out.println("---%<--- " + indexing.getUrl()); | ||
indexing.writeWholeLogTo(System.out); | ||
System.out.println("---%<--- "); | ||
} | ||
|
||
|
||
} | ||
|