33import hudson .AbortException ;
44import hudson .cli .CLICommand ;
55import hudson .model .Failure ;
6+ import hudson .util .FormValidation ;
67import net .sf .json .JSONObject ;
78import org .junit .Test ;
89import org .junit .runner .RunWith ;
@@ -33,11 +34,12 @@ public void simpleConfiguration() throws Exception {
3334 assertEquals ("Your parameter does not match the regular expression!" , d .getFailedValidationMessage ());
3435 assertEquals ("Some parameter" , d .getDescription ());
3536 Mockito .when (req .getParameterValues ("DUMMY" )).thenReturn (new String []{"test" });
36- assertEquals (new ValidatingStringParameterValue ("DUMMY" , "test" ), d .createValue (req ));
37+ ValidatingStringParameterValue v1 = new ValidatingStringParameterValue ("DUMMY" , "test" , ".+" , "" );
38+ assertEquals (v1 , d .createValue (req ));
3739 JSONObject jo = new JSONObject ();
38- ValidatingStringParameterValue v = new ValidatingStringParameterValue ("DUMMY" , "test2" );
39- Mockito .when (req .bindJSON (ValidatingStringParameterValue .class , jo )).thenReturn (v );
40- assertEquals (v , d .createValue (req , jo ));
40+ ValidatingStringParameterValue v2 = new ValidatingStringParameterValue ("DUMMY" , "test2" );
41+ Mockito .when (req .bindJSON (ValidatingStringParameterValue .class , jo )).thenReturn (v2 );
42+ assertEquals (v2 , d .createValue (req , jo ));
4143 }
4244
4345 @ Test (expected = Failure .class )
@@ -61,7 +63,9 @@ public void cliCommand() throws IOException, InterruptedException {
6163 ValidatingStringParameterDefinition d = new ValidatingStringParameterDefinition ("DUMMY" , "foo" , "\" .+" , "Your parameter does not match the regular expression!" , "Some parameter" );
6264 assertEquals (d .getDefaultParameterValue (),d .createValue (cliCommand , null ));
6365 Mockito .verifyNoInteractions (cliCommand );
64- assertEquals (new ValidatingStringParameterValue ("DUMMY" , "\" hello" ), d .createValue (cliCommand , "\" hello" ));
66+ ValidatingStringParameterValue v = new ValidatingStringParameterValue ("DUMMY" , "\" hello" );
67+ v .setRegex ("\" .+" );
68+ assertEquals (v , d .createValue (cliCommand , "\" hello" ));
6569 Mockito .verifyNoInteractions (cliCommand );
6670 }
6771
@@ -71,4 +75,18 @@ public void cliCommandFailure() throws IOException, InterruptedException {
7175 d .createValue (cliCommand , "hello" );
7276 Mockito .verifyNoInteractions (cliCommand );
7377 }
78+
79+ @ Test
80+ public void regexCheck () {
81+ ValidatingStringParameterDefinition .DescriptorImpl d = new ValidatingStringParameterDefinition .DescriptorImpl ();
82+ assertEquals (FormValidation .Kind .OK , d .doCheckRegex ("abc" ).kind );
83+ assertEquals (FormValidation .Kind .ERROR , d .doCheckRegex ("(dddd" ).kind );
84+ }
85+
86+ @ Test
87+ public void validationCheck () {
88+ ValidatingStringParameterDefinition .DescriptorImpl d = new ValidatingStringParameterDefinition .DescriptorImpl ();
89+ assertEquals (FormValidation .Kind .OK , d .doValidate ("abc" , "failed" , "abc" ).kind );
90+ assertEquals (FormValidation .Kind .ERROR , d .doValidate ("abc" , "failed" , "" ).kind );
91+ }
7492}
0 commit comments