1717package org.rundeck.client.tool.commands
1818
1919import org.rundeck.client.api.RundeckApi
20+ import org.rundeck.client.api.model.DateInfo
2021import org.rundeck.client.api.model.ExecOutput
2122import org.rundeck.client.api.model.Execution
2223import org.rundeck.client.api.model.JobFileUploadResult
@@ -33,6 +34,9 @@ import retrofit2.Retrofit
3334import retrofit2.mock.Calls
3435import spock.lang.Specification
3536import spock.lang.Unroll
37+
38+ import java.text.SimpleDateFormat
39+
3640/**
3741 * @author greg
3842 * @since 12/13/16
@@ -111,6 +115,43 @@ class RunSpec extends Specification {
111115 0 * api. _(* _)
112116 result == 0
113117
118+ }
119+ def " run at time supports multiple formats" () {
120+
121+ given :
122+ // round to seconds, since the date format does not include milliseconds
123+ long millis = Math . floor(System . currentTimeMillis() / 1000L ). toLong()
124+ Date timeToRun = new Date ((millis* 1000L )+ (3L * 1000L * 60L * 24L ))
125+ String dateString = new SimpleDateFormat (dateFormat). format(timeToRun)
126+
127+ def api = Mock (RundeckApi )
128+ RdTool rdTool = setupMock(api, 20 )
129+ def out = Mock (CommandOutput )
130+ Run command = new Run ()
131+ command. rdTool = rdTool
132+ command. rdOutput = out
133+
134+ command. options. project = ' ProjectName'
135+ command. options. job = ' a group/path/a job'
136+ command. options. setRunAtDate(new DateInfo (dateString))
137+
138+ when :
139+ def result = command. call()
140+
141+ then :
142+ 1 * api. listJobs(' ProjectName' , null , null , ' a job' , ' a group/path' ) >>
143+ Calls . response([new JobItem (id : ' fakeid' )])
144+ 1 * api. runJob(' fakeid' , {
145+ it. runAtTime== timeToRun
146+ }) >> Calls . response(new Execution (id : 123 , description : ' ' ))
147+ 0 * api. _(* _)
148+ result == 0
149+ where :
150+ dateFormat | _
151+ DateInfo . ISO | _
152+ DateInfo . ISO1 | _
153+ DateInfo . ISO2 | _
154+
114155 }
115156
116157 def " run command loglevel debug" () {
0 commit comments