49
49
import static org .junit .Assert .*;
50
50
import org .junit .ClassRule ;
51
51
import org .junit .Rule ;
52
- import org .junit .runners .model .Statement ;
53
52
import org .jvnet .hudson .test .BuildWatcher ;
54
53
import org .jvnet .hudson .test .Issue ;
55
- import org .jvnet .hudson .test .RestartableJenkinsRule ;
54
+ import org .jvnet .hudson .test .JenkinsSessionRule ;
56
55
57
56
public class SCMVarTest {
58
57
59
58
@ ClassRule public static BuildWatcher buildWatcher = new BuildWatcher ();
60
- @ Rule public RestartableJenkinsRule story = new RestartableJenkinsRule ();
59
+ @ Rule public JenkinsSessionRule story = new JenkinsSessionRule ();
61
60
@ Rule public GitSampleRepoRule sampleGitRepo = new GitSampleRepoRule ();
62
61
63
- @ Test public void scmPickle () {
64
- story .addStep (new Statement () {
65
- @ Override public void evaluate () throws Throwable {
62
+ @ Test public void scmPickle () throws Throwable {
63
+ story .then (j -> {
66
64
sampleGitRepo .init ();
67
65
sampleGitRepo .write ("Jenkinsfile" , "def _scm = scm; semaphore 'wait'; node {checkout _scm; echo readFile('file')}" );
68
66
sampleGitRepo .write ("file" , "initial content" );
69
67
sampleGitRepo .git ("add" , "Jenkinsfile" );
70
68
sampleGitRepo .git ("commit" , "--all" , "--message=flow" );
71
- WorkflowMultiBranchProject mp = story . j .jenkins .createProject (WorkflowMultiBranchProject .class , "p" );
69
+ WorkflowMultiBranchProject mp = j .jenkins .createProject (WorkflowMultiBranchProject .class , "p" );
72
70
mp .getSourcesList ().add (new BranchSource (new GitSCMSource (null , sampleGitRepo .toString (), "" , "*" , "" , false ), new DefaultBranchPropertyStrategy (new BranchProperty [0 ])));
73
71
WorkflowJob p = WorkflowMultiBranchProjectTest .scheduleAndFindBranchProject (mp , "master" );
74
72
SemaphoreStep .waitForStart ("wait/1" , null );
75
73
WorkflowRun b1 = p .getLastBuild ();
76
74
assertNotNull (b1 );
77
- }
78
75
});
79
- story .addStep (new Statement () {
80
- @ Override public void evaluate () throws Throwable {
76
+ story .then (j -> {
81
77
SemaphoreStep .success ("wait/1" , null );
82
- WorkflowJob p = story . j .jenkins .getItemByFullName ("p/master" , WorkflowJob .class );
78
+ WorkflowJob p = j .jenkins .getItemByFullName ("p/master" , WorkflowJob .class );
83
79
assertNotNull (p );
84
80
WorkflowRun b1 = p .getLastBuild ();
85
81
assertNotNull (b1 );
86
82
assertEquals (1 , b1 .getNumber ());
87
- story . j .assertLogContains ("initial content" , story . j .waitForCompletion (b1 ));
83
+ j .assertLogContains ("initial content" , j .waitForCompletion (b1 ));
88
84
SCMBinderTest .assertRevisionAction (b1 );
89
- }
90
85
});
91
86
}
92
87
93
88
@ Issue ("JENKINS-30222" )
94
- @ Test public void globalVariable () {
95
- story .addStep (new Statement () {
96
- @ Override public void evaluate () throws Throwable {
89
+ @ Test public void globalVariable () throws Throwable {
90
+ story .then (j -> {
97
91
// Set up a standardJob definition:
98
92
File lib = new File (Jenkins .get ().getRootDir (), "somelib" );
99
93
LibraryConfiguration cfg = new LibraryConfiguration ("somelib" , new LocalRetriever (lib ));
@@ -121,12 +115,11 @@ public class SCMVarTest {
121
115
sampleGitRepo .git ("add" , "resource" );
122
116
sampleGitRepo .git ("commit" , "--all" , "--message=flow" );
123
117
// And run:
124
- WorkflowMultiBranchProject mp = story . j .jenkins .createProject (WorkflowMultiBranchProject .class , "p" );
118
+ WorkflowMultiBranchProject mp = j .jenkins .createProject (WorkflowMultiBranchProject .class , "p" );
125
119
mp .getSourcesList ().add (new BranchSource (new GitSCMSource (null , sampleGitRepo .toString (), "" , "*" , "" , false ), new DefaultBranchPropertyStrategy (new BranchProperty [0 ])));
126
120
WorkflowJob p = WorkflowMultiBranchProjectTest .scheduleAndFindBranchProject (mp , "master" );
127
- WorkflowRun b = story .j .assertBuildStatusSuccess (p .scheduleBuild2 (0 ));
128
- story .j .assertLogContains ("loaded resource content" , b );
129
- }
121
+ WorkflowRun b = j .assertBuildStatusSuccess (p .scheduleBuild2 (0 ));
122
+ j .assertLogContains ("loaded resource content" , b );
130
123
});
131
124
}
132
125
@@ -145,19 +138,17 @@ private static final class LocalRetriever extends LibraryRetriever {
145
138
}
146
139
147
140
@ Issue ("JENKINS-31386" )
148
- @ Test public void standaloneProject () {
149
- story .addStep (new Statement () {
150
- @ Override public void evaluate () throws Throwable {
141
+ @ Test public void standaloneProject () throws Throwable {
142
+ story .then (j -> {
151
143
sampleGitRepo .init ();
152
144
sampleGitRepo .write ("Jenkinsfile" , "node {checkout scm; echo readFile('file')}" );
153
145
sampleGitRepo .write ("file" , "some content" );
154
146
sampleGitRepo .git ("add" , "Jenkinsfile" );
155
147
sampleGitRepo .git ("commit" , "--all" , "--message=flow" );
156
- WorkflowJob p = story . j .jenkins .createProject (WorkflowJob .class , "p" );
148
+ WorkflowJob p = j .jenkins .createProject (WorkflowJob .class , "p" );
157
149
p .setDefinition (new CpsScmFlowDefinition (new GitStep (sampleGitRepo .toString ()).createSCM (), "Jenkinsfile" ));
158
- WorkflowRun b = story .j .assertBuildStatusSuccess (p .scheduleBuild2 (0 ));
159
- story .j .assertLogContains ("some content" , b );
160
- }
150
+ WorkflowRun b = j .assertBuildStatusSuccess (p .scheduleBuild2 (0 ));
151
+ j .assertLogContains ("some content" , b );
161
152
});
162
153
}
163
154
0 commit comments