1010import hudson .model .FreeStyleProject ;
1111import hudson .model .Result ;
1212import hudson .slaves .DumbSlave ;
13+ import org .htmlunit .WebAssert ;
1314import org .htmlunit .html .*;
1415import org .jenkinsci .plugins .workflow .cps .CpsFlowDefinition ;
1516import org .jenkinsci .plugins .workflow .job .WorkflowJob ;
@@ -54,76 +55,61 @@ public void testSetup() throws IOException {
5455 public void testTearDown () {
5556 this .project = null ;
5657 this .scriptBuilder = null ;
57- MatlabRootSetup .matlabInstDescriptor = null ;
58+ Utilities .matlabInstDescriptor = null ;
5859 this .buildWrapper = null ;
5960 }
6061
61- public void useCommandFreeStyle (String command ) {
62- scriptBuilder .setMatlabCommand (TestData .getPropValues ("matlab.command" ));
63- project .getBuildersList ().add (scriptBuilder );
64- }
65-
6662 @ Test
6763 public void verifyGlobalToolForFreeStyle () throws Exception {
6864 // Adding the MATLAB Global tool
69- MatlabRootSetup .setMatlabInstallation ("MATLAB_PATH" , MatlabRootSetup .getMatlabRoot (), jenkins );
65+ Utilities .setMatlabInstallation ("MATLAB_PATH" , Utilities .getMatlabRoot (), jenkins );
7066
7167 // Selecting MATLAB that is defined as Global tool
7268 MatlabInstallation _inst = MatlabInstallation .getInstallation ("MATLAB_PATH" );
7369 MatlabBuildWrapperContent content = new MatlabBuildWrapperContent (_inst .getName (), null );
7470 buildWrapper .setMatlabBuildWrapperContent (content );
7571 project .getBuildWrappersList ().add (buildWrapper );
76- useCommandFreeStyle ("version" );
72+ scriptBuilder .setMatlabCommand ("disp('apple')" );
73+ project .getBuildersList ().add (scriptBuilder );
7774
7875 FreeStyleBuild build = project .scheduleBuild2 (0 ).get ();
7976
8077 jenkins .assertLogContains (_inst .getHome (), build );
8178 jenkins .assertBuildStatus (Result .SUCCESS , build );
79+ jenkins .assertLogContains ("apple" , build );
8280 }
8381
8482 @ Test
8583 public void verifyBuildFailsForIncorrectToolPath () throws Exception {
8684 // Adding the MATLAB Global tool
87- MatlabRootSetup .setMatlabInstallation ("MATLAB_PATH" , "matlab/incorrect/path" , jenkins );
88- jenkins .configRoundtrip ();
85+ Utilities .setMatlabInstallation ("MATLAB_PATH" , "matlab/incorrect/path" , jenkins );
8986
9087 // Selecting MATLAB that is defined as Global tool
9188 MatlabInstallation _inst = MatlabInstallation .getInstallation ("MATLAB_PATH" );
9289 MatlabBuildWrapperContent content = new MatlabBuildWrapperContent (_inst .getName (), null );
9390 buildWrapper .setMatlabBuildWrapperContent (content );
9491 project .getBuildWrappersList ().add (buildWrapper );
9592
96- scriptBuilder .setMatlabCommand (TestData . getPropValues ( "matlab.command" ) );
93+ scriptBuilder .setMatlabCommand ("ver" );
9794 project .getBuildersList ().add (scriptBuilder );
9895
9996 FreeStyleBuild build = project .scheduleBuild2 (0 ).get ();
10097
10198 jenkins .assertBuildStatus (Result .FAILURE , build );
10299 jenkins .assertLogContains ("Verify global tool configuration for the specified node." , build );
103- }
104-
105- //Modify it to use the Custom Option
106-
107- public void verifyUseMATLABVersionBuildPasses () throws Exception {
108- HtmlPage configurePage = jenkins .createWebClient ().goTo ("job/test0/configure" );
109- HtmlTextInput matlabRoot =configurePage .getElementByName ("_.matlabRootFolder" );
110- matlabRoot .setValueAttribute (MatlabRootSetup .getMatlabRoot ());
111- HtmlButton saveButton = (HtmlButton ) configurePage .getElementByName ("Submit" ).getFirstChild ().getFirstChild ();
112- RunMatlabCommandBuilder tester =
113- new RunMatlabCommandBuilder ();
114- tester .setMatlabCommand (TestData .getPropValues ("matlab.command" ));
115- project .getBuildersList ().add (tester );
116- FreeStyleBuild build = project .scheduleBuild2 (0 ).get ();
117- String build_log = jenkins .getLog (build );
118- jenkins .assertBuildStatus (Result .SUCCESS , build );
100+ jenkins .assertLogContains ("matlab/incorrect/path" , build );
119101 }
120102
121103 @ Test
122104 public void verifyAllToolsAreAvailable () throws Exception {
123105 // Adding the Global tools
124- MatlabRootSetup .setMatlabInstallation ("MATLAB_PATH_1" , MatlabRootSetup .getMatlabRoot (), jenkins );
125- MatlabRootSetup .setMatlabInstallation ("MATLAB_PATH_2" , MatlabRootSetup .getMatlabRoot ().replace (TestData .getPropValues ("matlab.version" ), "R2020a" ), jenkins );
126- jenkins .configRoundtrip ();
106+ String matlabRoot = System .getenv ("MATLAB_ROOT" );
107+ String matlabRoot22b = System .getenv ("MATLAB_ROOT_22b" );
108+ Assume .assumeTrue ("Not running tests as MATLAB_ROOT_22b environment variable is not defined" , matlabRoot22b != null && !matlabRoot22b .isEmpty ());
109+
110+ Utilities .setMatlabInstallation ("MATLAB_PATH_1" , matlabRoot , jenkins );
111+ Utilities .setMatlabInstallation ("MATLAB_PATH_2" , matlabRoot22b , jenkins );
112+
127113 // Getting the Web page for UI testing
128114 HtmlPage configurePage = jenkins .createWebClient ().goTo ("job/test0/configure" );
129115 HtmlCheckBoxInput matlabver =configurePage .getElementByName ("com-mathworks-ci-UseMatlabVersionBuildWrapper" );
@@ -144,60 +130,10 @@ public void verifyAllToolsAreAvailable() throws Exception {
144130 assertTrue (allOptionsAvailable );
145131 }
146132
147-
148- @ Test
149- public void verifyNodes () throws Exception {
150- DumbSlave slave = jenkins .createSlave ("slave" ,"Slave_machine" ,null );
151- // project.setAssignedNode(slave);
152- // Adding the MATLAB Global tool
153- MatlabRootSetup .setMatlabInstallation ("MATLAB_PATH" , MatlabRootSetup .getMatlabRoot (), jenkins );
154-
155- // Selecting MATLAB that is defined as Global tool
156- MatlabInstallation _inst = MatlabInstallation .getInstallation ("MATLAB_PATH" );
157- MatlabBuildWrapperContent content = new MatlabBuildWrapperContent (_inst .getName (), null );
158- buildWrapper .setMatlabBuildWrapperContent (content );
159- project .getBuildWrappersList ().add (buildWrapper );
160- useCommandFreeStyle ("version" );
161-
162- FreeStyleBuild build = project .scheduleBuild2 (0 ).get ();
163-
164- jenkins .assertLogContains (_inst .getHome (), build );
165- String build_log = jenkins .getLog (build );
166-
167- jenkins .assertBuildStatus (Result .SUCCESS , build );
168- }
169-
170- /*
171- * Test to verify if Matrix build passes .
172- */
173-
174- @ Test
175- public void verifyToolMatrixPreference () throws Exception {
176- List <String > list = new ArrayList <>(Arrays .asList ("MATLAB_PATH_1" , "MATLAB_PATH_22b" ));
177- MatlabInstallationAxis axis = new MatlabInstallationAxis (list );
178- MatrixProject matrixProject = jenkins .createProject (MatrixProject .class );;
179- matrixProject .setAxes (new AxisList (axis ));
180-
181- String matlabRoot = MatlabRootSetup .getMatlabRoot ();
182- this .buildWrapper .setMatlabBuildWrapperContent (new MatlabBuildWrapperContent (Message .getValue ("matlab.custom.location" ), matlabRoot ));
183- matrixProject .getBuildWrappersList ().add (buildWrapper );
184-
185- scriptBuilder .setMatlabCommand ("disp 'apple'" );
186- matrixProject .getBuildersList ().add (scriptBuilder );
187- MatrixBuild build = matrixProject .scheduleBuild2 (0 ).get ();
188- List <MatrixRun > runs = build .getRuns ();
189- // TODO: add more relevant verification statement
190- for (MatrixRun run : runs ) {
191- jenkins .assertLogContains ("apple" , run );
192- }
193- jenkins .assertBuildStatus (Result .SUCCESS ,build );
194- }
195-
196- // Verify "Use MATLAB Version" takes precedence over Global tools in Matrix Project
197133 @ Test
198134 public void verifyGlobalToolMatrix () throws Exception {
199- MatlabRootSetup .setMatlabInstallation ("MATLAB_PATH_1" , MatlabRootSetup .getMatlabRoot (), jenkins );
200- MatlabRootSetup .setMatlabInstallation ("MATLAB_PATH_2" , MatlabRootSetup .getMatlabRoot (), jenkins );
135+ Utilities .setMatlabInstallation ("MATLAB_PATH_1" , Utilities .getMatlabRoot (), jenkins );
136+ Utilities .setMatlabInstallation ("MATLAB_PATH_2" , Utilities .getMatlabRoot (), jenkins );
201137
202138 List <String > list = new ArrayList <>(Arrays .asList ("MATLAB_PATH_1" , "MATLAB_PATH_2" ));
203139 MatlabInstallationAxis axis = new MatlabInstallationAxis (list );
@@ -206,11 +142,8 @@ public void verifyGlobalToolMatrix() throws Exception {
206142
207143 scriptBuilder .setMatlabCommand ("version" );
208144 matrixProject .getBuildersList ().add (scriptBuilder );
209- System .out .println ("STARTING BUILD" );
210145 MatrixBuild build = matrixProject .scheduleBuild2 (0 ).get ();
211- System .out .println ("SCHEDULED BUILD" );
212146 List <MatrixRun > runs = build .getRuns ();
213- System .out .println ("RAN BUILD" );
214147 // ToDo: Add more relevant verification statement
215148 for (MatrixRun run : runs ) {
216149 String matlabName = run .getBuildVariables ().get ("MATLAB" );
@@ -222,11 +155,10 @@ public void verifyGlobalToolMatrix() throws Exception {
222155 // Tool config
223156 @ Test
224157 public void verifyGlobalToolDSLPipeline () throws Exception {
225- MatlabRootSetup .setMatlabInstallation ("MATLAB_PATH_1" , MatlabRootSetup .getMatlabRoot (), jenkins );
226- MatlabRootSetup .setMatlabInstallation ("MATLAB_PATH_2" , MatlabRootSetup .getMatlabRoot ().replace ("R2020b" , "R2020a" ), jenkins );
158+ Utilities .setMatlabInstallation ("MATLAB_PATH_1" , Utilities .getMatlabRoot (), jenkins );
227159 String script = "pipeline {\n " +
228160 " agent any\n " +
229- MatlabRootSetup .getEnvironmentDSL () + "\n " +
161+ Utilities .getEnvironmentDSL () + "\n " +
230162 " tools {\n " +
231163 " matlab 'MATLAB_PATH_1'\n " +
232164 " }\n " +
@@ -244,8 +176,7 @@ public void verifyGlobalToolDSLPipeline() throws Exception {
244176 }
245177 @ Test
246178 public void verifyGlobalToolScriptedPipeline () throws Exception {
247- MatlabRootSetup .setMatlabInstallation ("MATLAB_PATH_1" , MatlabRootSetup .getMatlabRoot (), jenkins );
248- MatlabRootSetup .setMatlabInstallation ("MATLAB_PATH_2" , MatlabRootSetup .getMatlabRoot ().replace ("R2020b" , "R2020a" ), jenkins );
179+ Utilities .setMatlabInstallation ("MATLAB_PATH_1" , Utilities .getMatlabRoot (), jenkins );
249180 String script = "node {\n " +
250181 " def matlabver\n " +
251182 " stage('Run MATLAB Command') {\n " +
@@ -262,10 +193,14 @@ public void verifyGlobalToolScriptedPipeline() throws Exception {
262193 jenkins .assertBuildStatus (Result .SUCCESS , build );
263194 }
264195
196+ /*
197+ * Test to verify if Matrix build passes .
198+ */
199+
265200 private WorkflowRun getPipelineBuild (String script ) throws Exception {
266201 WorkflowJob project = jenkins .createProject (WorkflowJob .class );
267202 project .setDefinition (new CpsFlowDefinition (script ,true ));
268203 return project .scheduleBuild2 (0 ).get ();
269204 }
270205
271- }
206+ }
0 commit comments