package hudson.plugins.jira;

import hudson.cli.BuildCommand;
import hudson.cli.CLICommandInvoker;
import hudson.model.FreeStyleProject;
import hudson.model.ParametersDefinitionProperty;
import hudson.plugins.jira.listissuesparameter.JiraIssueParameterDefinition;
import hudson.plugins.jira.versionparameter.JiraVersionParameterDefinition;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static org.hamcrest.MatcherAssert.assertThat;
import static hudson.cli.CLICommandInvoker.Matcher.succeeded;


public class CliParameterTest {

    @Rule
    public JenkinsRule jenkins = new JenkinsRule();

    @Test
    public void jiraIssueParameterViaCli() throws Exception {
        FreeStyleProject project = jenkins.createFreeStyleProject();

        project.addProperty(
            new ParametersDefinitionProperty(
                new JiraIssueParameterDefinition("jiraissue", "description", "filter")
            )
        );

        CLICommandInvoker invoker = new CLICommandInvoker(jenkins, new BuildCommand());
        CLICommandInvoker.Result result = invoker.invokeWithArgs(project.getName(), "-p", "jiraissue=TEST-1");
        assertThat(result, succeeded());
    }

    @Test
    public void jiraVersionParameterViaCli() throws Exception {
        FreeStyleProject project = jenkins.createFreeStyleProject();

        project.addProperty(
            new ParametersDefinitionProperty(
                new JiraVersionParameterDefinition("jiraversion", "description", "PROJ", "RELEASE", "true", "false")
            )
        );

        CLICommandInvoker invoker = new CLICommandInvoker(jenkins, new BuildCommand());
        CLICommandInvoker.Result result = invoker.invokeWithArgs(project.getName(), "-p", "jiraversion=1.0");
        assertThat(result, succeeded());
    }
}

@@ -23,16 +23,132 @@
 .jira;%0A%0A
+import static hudson.cli.CLICommandInvoker.Matcher.succeeded;%0Aimport static org.hamcrest.MatcherAssert.assertThat;%0A%0A
 import h
@@ -542,125 +542,8 @@
 e;%0A%0A
-import static org.hamcrest.MatcherAssert.assertThat;%0Aimport static hudson.cli.CLICommandInvoker.Matcher.succeeded;%0A%0A%0A
 publ
@@ -577,19 +577,13 @@
 %0A%0A  
- 
- 
 @Rule
-%0A   
  pub
@@ -628,18 +628,16 @@
 ule();%0A%0A
-  
   @Test%0A
@@ -630,34 +630,32 @@
 e();%0A%0A  @Test%0A  
- 
- 
 public void jira
@@ -688,36 +688,32 @@
 ows Exception %7B%0A
-    
     FreeStylePro
@@ -758,36 +758,32 @@
 Project();%0A%0A    
-   
- 
 project.addPrope
@@ -779,36 +779,32 @@
 ct.addProperty(%0A
-    
         new Para
@@ -821,36 +821,32 @@
 nitionProperty(%0A
-    
             new 
@@ -915,39 +915,17 @@
 er%22)
-%0A            )%0A        
+)
 );%0A%0A    
     
@@ -912,36 +912,32 @@
 ilter%22)));%0A%0A    
-   
- 
 CLICommandInvoke
@@ -992,36 +992,32 @@
 uildCommand());%0A
-    
     CLICommandIn
@@ -1029,32 +1029,40 @@
 .Result result =
+%0A       
  invoker.invokeW
@@ -1111,28 +1111,24 @@
 e=TEST-1%22);%0A
-    
     assertTh
@@ -1156,27 +1156,21 @@
 ));%0A
-  
   %7D%0A%0A  
- 
- 
 @Test%0A
-  
   pu
@@ -1231,20 +1231,16 @@
 n %7B%0A    
-  
-  
 FreeStyl
@@ -1289,28 +1289,24 @@
 Project();%0A%0A
-    
     project.
@@ -1322,28 +1322,24 @@
 ty(%0A        
-  
-  
 new Paramete
@@ -1352,36 +1352,32 @@
 nitionProperty(%0A
-    
             new 
@@ -1403,24 +1403,41 @@
 rDefinition(
+%0A                
 %22jiraversion
@@ -1493,39 +1493,13 @@
 se%22)
-%0A            )%0A        );%0A%0A    
+));%0A%0A
     
@@ -1582,20 +1582,16 @@
 ));%0A    
-  
-  
 CLIComma
@@ -1615,16 +1615,24 @@
 result =
+%0A       
  invoker
@@ -1692,20 +1692,16 @@
 =1.0%22);%0A
-    
     asse
@@ -1729,16 +1729,14 @@
 ded());%0A
-  
   %7D%0A%7D%0A

Reformat code