99import hudson .model .FreeStyleBuild ;
1010import hudson .model .FreeStyleProject ;
1111import hudson .model .Result ;
12- import hudson .slaves .DumbSlave ;
13- import org .htmlunit .WebAssert ;
1412import org .htmlunit .html .*;
1513import org .jenkinsci .plugins .workflow .cps .CpsFlowDefinition ;
1614import org .jenkinsci .plugins .workflow .job .WorkflowJob ;
1715import org .jenkinsci .plugins .workflow .job .WorkflowRun ;
1816import org .junit .*;
19- import org .junit .rules .Timeout ;
2017import org .jvnet .hudson .test .JenkinsRule ;
2118
2219import java .io .IOException ;
2320import java .util .ArrayList ;
2421import java .util .Arrays ;
2522import java .util .List ;
2623
27- import static junit .framework .TestCase .assertTrue ;
24+ import static org .apache .commons .lang3 .StringUtils .*;
25+ import static org .junit .Assert .assertEquals ;
2826
2927public class GlobalToolIT {
3028 private FreeStyleProject project ;
3129 private RunMatlabCommandBuilder scriptBuilder ;
3230 private UseMatlabVersionBuildWrapper buildWrapper ;
33-
34- @ Rule
35- public Timeout timeout = Timeout .seconds (0 );
36-
3731 @ Rule
3832 public JenkinsRule jenkins = new JenkinsRule ();
3933
@@ -65,18 +59,19 @@ public void verifyGlobalToolForFreeStyle() throws Exception{
6559 Utilities .setMatlabInstallation ("MATLAB_PATH" , Utilities .getMatlabRoot (), jenkins );
6660
6761 // Selecting MATLAB that is defined as Global tool
68- MatlabInstallation _inst = MatlabInstallation .getInstallation ("MATLAB_PATH" );
69- MatlabBuildWrapperContent content = new MatlabBuildWrapperContent (_inst .getName (), null );
62+ MatlabInstallation inst = MatlabInstallation .getInstallation ("MATLAB_PATH" );
63+ MatlabBuildWrapperContent content = new MatlabBuildWrapperContent (inst .getName (), null );
7064 buildWrapper .setMatlabBuildWrapperContent (content );
7165 project .getBuildWrappersList ().add (buildWrapper );
7266 scriptBuilder .setMatlabCommand ("disp('apple')" );
7367 project .getBuildersList ().add (scriptBuilder );
7468
7569 FreeStyleBuild build = project .scheduleBuild2 (0 ).get ();
7670
77- jenkins .assertLogContains (_inst .getHome (), build );
71+ jenkins .assertLogContains (inst .getHome (), build );
7872 jenkins .assertBuildStatus (Result .SUCCESS , build );
7973 jenkins .assertLogContains ("apple" , build );
74+ assertEquals (countMatches (jenkins .getLog (build ), "apple" ), 2 );
8075 }
8176
8277 @ Test
@@ -85,8 +80,8 @@ public void verifyBuildFailsForIncorrectToolPath() throws Exception{
8580 Utilities .setMatlabInstallation ("MATLAB_PATH" , "matlab/incorrect/path" , jenkins );
8681
8782 // Selecting MATLAB that is defined as Global tool
88- MatlabInstallation _inst = MatlabInstallation .getInstallation ("MATLAB_PATH" );
89- MatlabBuildWrapperContent content = new MatlabBuildWrapperContent (_inst .getName (), null );
83+ MatlabInstallation inst = MatlabInstallation .getInstallation ("MATLAB_PATH" );
84+ MatlabBuildWrapperContent content = new MatlabBuildWrapperContent (inst .getName (), null );
9085 buildWrapper .setMatlabBuildWrapperContent (content );
9186 project .getBuildWrappersList ().add (buildWrapper );
9287
@@ -96,6 +91,7 @@ public void verifyBuildFailsForIncorrectToolPath() throws Exception{
9691 FreeStyleBuild build = project .scheduleBuild2 (0 ).get ();
9792
9893 jenkins .assertBuildStatus (Result .FAILURE , build );
94+ // Note: This message might change in future based on Jenkins changes
9995 jenkins .assertLogContains ("Verify global tool configuration for the specified node." , build );
10096 jenkins .assertLogContains ("MATLAB_PATH" , build );
10197 }
@@ -112,22 +108,13 @@ public void verifyAllToolsAreAvailable() throws Exception {
112108
113109 // Getting the Web page for UI testing
114110 HtmlPage configurePage = jenkins .createWebClient ().goTo ("job/test0/configure" );
115- HtmlCheckBoxInput matlabver = configurePage .getElementByName ("com-mathworks-ci-UseMatlabVersionBuildWrapper" );
116- matlabver .setChecked (true );
111+ HtmlCheckBoxInput matlabVer = configurePage .getElementByName ("com-mathworks-ci-UseMatlabVersionBuildWrapper" );
112+ matlabVer .setChecked (true );
117113 Thread .sleep (2000 );
118- List <HtmlSelect > matlabver_1 =configurePage .getByXPath ("//select[contains(@class, \" dropdownList\" )]" );
119- // One of the drop downlists should have three options
120- boolean allOptionsAvailable = false ;
121- for (HtmlSelect e : matlabver_1 ){
122- if (e .getOptionSize () == 3 ){
123- if (e .getOption (0 ).getValueAttribute ().equals ("MATLAB_PATH_1" ) &&
124- e .getOption (1 ).getValueAttribute ().equals ("MATLAB_PATH_2" ) &&
125- e .getOption (2 ).getValueAttribute ().equals ("Custom..." )) {
126- allOptionsAvailable = true ;
127- }
128- }
129- }
130- assertTrue (allOptionsAvailable );
114+ HtmlSelect matlabOptions = (HtmlSelect ) configurePage .getByXPath ("//select[contains(@class, \" dropdownList\" )]" ).get (1 );
115+ assertEquals (matlabOptions .getOption (0 ).getValueAttribute (),"MATLAB_PATH_1" );
116+ assertEquals (matlabOptions .getOption (1 ).getValueAttribute (),"MATLAB_PATH_2" );
117+ assertEquals (matlabOptions .getOption (2 ).getValueAttribute (),"Custom..." );
131118 }
132119
133120 @ Test
@@ -158,21 +145,21 @@ public void verifyGlobalToolDSLPipeline() throws Exception {
158145 Utilities .setMatlabInstallation ("MATLAB_PATH_1" , Utilities .getMatlabRoot (), jenkins );
159146 String script = "pipeline {\n " +
160147 " agent any\n " +
161- Utilities .getEnvironmentDSL () + "\n " +
162148 " tools {\n " +
163149 " matlab 'MATLAB_PATH_1'\n " +
164150 " }\n " +
165151 " stages{\n " +
166152 " stage('Run MATLAB Command') {\n " +
167153 " steps\n " +
168154 " {\n " +
169- " runMATLABCommand 'version '\n " +
155+ " runMATLABCommand 'matlabroot '\n " +
170156 " } \n " +
171157 " } \n " +
172158 " } \n " +
173159 "}" ;
174160 WorkflowRun build = getPipelineBuild (script );
175161 jenkins .assertBuildStatus (Result .SUCCESS ,build );
162+ assertEquals (countMatches (jenkins .getLog (build ), Utilities .getMatlabRoot ()), 1 );
176163 }
177164 @ Test
178165 public void verifyGlobalToolScriptedPipeline () throws Exception {
@@ -186,17 +173,14 @@ public void verifyGlobalToolScriptedPipeline() throws Exception {
186173 " }else{\n " +
187174 " env.PATH = \" ${matlabver}\\ \\ bin;${env.PATH}\" // Windows agent\n " +
188175 " } \n " +
189- " runMATLABCommand 'version '\n " +
176+ " runMATLABCommand 'matlabroot '\n " +
190177 " }\n " +
191178 "}" ;
192179 WorkflowRun build = getPipelineBuild (script );
193180 jenkins .assertBuildStatus (Result .SUCCESS , build );
181+ assertEquals (countMatches (jenkins .getLog (build ), Utilities .getMatlabRoot ()), 1 );
194182 }
195183
196- /*
197- * Test to verify if Matrix build passes .
198- */
199-
200184 private WorkflowRun getPipelineBuild (String script ) throws Exception {
201185 WorkflowJob project = jenkins .createProject (WorkflowJob .class );
202186 project .setDefinition (new CpsFlowDefinition (script ,true ));
0 commit comments