11package hudson .plugins .validating_string_parameter ;
22
3+ import hudson .Functions ;
4+ import hudson .model .FreeStyleBuild ;
5+ import hudson .model .FreeStyleProject ;
6+ import hudson .model .ParameterValue ;
7+ import hudson .model .ParametersAction ;
38import hudson .model .ParametersDefinitionProperty ;
9+ import hudson .tasks .BatchFile ;
10+ import hudson .tasks .Shell ;
11+ import org .htmlunit .html .DomNode ;
12+ import org .htmlunit .html .HtmlButton ;
13+ import org .htmlunit .html .HtmlPage ;
414import org .jenkinsci .plugins .workflow .cps .CpsFlowDefinition ;
515import org .jenkinsci .plugins .workflow .job .WorkflowJob ;
616import org .junit .Rule ;
717import org .junit .Test ;
818import org .jvnet .hudson .test .JenkinsRule ;
919
20+ import java .util .List ;
21+
1022import static org .hamcrest .MatcherAssert .assertThat ;
23+ import static org .hamcrest .Matchers .empty ;
24+ import static org .hamcrest .Matchers .equalTo ;
25+ import static org .hamcrest .Matchers .instanceOf ;
1126import static org .hamcrest .Matchers .is ;
27+ import static org .hamcrest .Matchers .not ;
1228import static org .hamcrest .Matchers .notNullValue ;
1329import static org .hamcrest .Matchers .nullValue ;
1430
@@ -29,4 +45,30 @@ public void pipeline() throws Exception {
2945 r .buildAndAssertSuccess (p );
3046 assertThat (p .getProperty (ParametersDefinitionProperty .class ), is (notNullValue ()));
3147 }
48+
49+ @ Test
50+ public void freestyle () throws Exception {
51+ FreeStyleProject p = r .createProject (FreeStyleProject .class , "fs" );
52+ p .getBuildersList ().add (Functions .isWindows () ? new BatchFile ("echo test" ) : new Shell ("echo test" ));
53+
54+ ValidatingStringParameterDefinition def = new ValidatingStringParameterDefinition ("name" , "defVal" , "\\ w+" , "Value must match the following pattern: \\ w+" );
55+ p .addProperty (new ParametersDefinitionProperty (def ));
56+
57+ try (JenkinsRule .WebClient wc = r .createWebClient ()) {
58+ wc .setThrowExceptionOnFailingStatusCode (false );
59+ HtmlPage htmlPage = wc .goTo ("job/fs/build" );
60+ HtmlButton buildButton = htmlPage .querySelector (".jenkins-button--primary" );
61+ buildButton .click ();
62+ }
63+
64+ r .waitUntilNoActivity ();
65+ List <ParameterValue > parameters = p .getLastSuccessfulBuild ().getAction (ParametersAction .class ).getParameters ();
66+ assertThat (parameters , is (not (empty ())));
67+ ParameterValue parameterValue = parameters .get (0 );
68+ assertThat (parameterValue , is (instanceOf (ValidatingStringParameterValue .class )));
69+ ValidatingStringParameterValue val = (ValidatingStringParameterValue ) parameterValue ;
70+ assertThat (val .getRegex (), is (equalTo ("\\ w+" )));
71+ assertThat (val .getValue (), is (equalTo ("defVal" )));
72+ assertThat (val .getName (), is (equalTo ("name" )));
73+ }
3274}
0 commit comments