diff --git a/build.gradle b/build.gradle index daf45496..f8da030c 100644 --- a/build.gradle +++ b/build.gradle @@ -197,6 +197,7 @@ dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' testCompile 'com.squareup.retrofit2:retrofit-mock:2.1.0' + testCompile 'com.squareup.okhttp3:mockwebserver:3.4.1' testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.19' testCompile "org.codehaus.groovy:groovy-all:2.3.7" testCompile "org.spockframework:spock-core:0.7-groovy-2.0" diff --git a/src/main/java/org/rundeck/client/api/model/DateInfo.java b/src/main/java/org/rundeck/client/api/model/DateInfo.java index c983cc68..5516fb60 100644 --- a/src/main/java/org/rundeck/client/api/model/DateInfo.java +++ b/src/main/java/org/rundeck/client/api/model/DateInfo.java @@ -16,6 +16,7 @@ package org.rundeck.client.api.model; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.rundeck.client.util.Format; @@ -28,13 +29,15 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class DateInfo { public static final String ISO = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - public final String date; + public String date; public long unixtime; public DateInfo(final String date) { this.date = date; } + public DateInfo() { + } public Date toDate() throws ParseException { return toDate(ISO); } diff --git a/src/test/groovy/org/rundeck/client/tool/commands/ExecutionsSpec.groovy b/src/test/groovy/org/rundeck/client/tool/commands/ExecutionsSpec.groovy index 374efb4b..6ffdfa88 100644 --- a/src/test/groovy/org/rundeck/client/tool/commands/ExecutionsSpec.groovy +++ b/src/test/groovy/org/rundeck/client/tool/commands/ExecutionsSpec.groovy @@ -17,10 +17,17 @@ package org.rundeck.client.tool.commands import com.simplifyops.toolbelt.CommandOutput +import okhttp3.mockwebserver.MockResponse +import okhttp3.mockwebserver.MockWebServer +import okhttp3.mockwebserver.RecordedRequest import org.rundeck.client.api.RundeckApi import org.rundeck.client.api.model.ExecOutput +import org.rundeck.client.api.model.Execution +import org.rundeck.client.tool.AppConfig +import org.rundeck.client.tool.RdApp import org.rundeck.client.util.Client import retrofit2.Retrofit +import retrofit2.converter.jackson.JacksonConverterFactory import retrofit2.mock.Calls import spock.lang.Specification @@ -84,4 +91,61 @@ class ExecutionsSpec extends Specification { 'scheduled' | false | true | 'failed' | false } + + def "parse execution"() { + given: + MockWebServer server = new MockWebServer(); + server.enqueue(new MockResponse().setBody('''{ + "id": 5418, + "href": "http://ecto1.local:4440/api/19/execution/5418", + "permalink": "http://ecto1.local:4440/project/adubs/execution/show/5418", + "status": "succeeded", + "project": "adubs", + "user": "admin", + "date-started": { + "unixtime": 1492043359634, + "date": "2017-04-13T00:29:19Z" + }, + "date-ended": { + "unixtime": 1492043360117, + "date": "2017-04-13T00:29:20Z" + }, + "job": { + "id": "58d4de5d-5aac-438b-9b0f-252b46c9d117", + "averageDuration": 926, + "name": "asdf", + "group": "", + "project": "adubs", + "description": "fff", + "href": "http://ecto1.local:4440/api/19/job/58d4de5d-5aac-438b-9b0f-252b46c9d117", + "permalink": "http://ecto1.local:4440/project/adubs/job/show/58d4de5d-5aac-438b-9b0f-252b46c9d117" + }, + "description": "echo blah blah", + "argstring": null, + "serverUUID": "3425B691-7319-4EEE-8425-F053C628B4BA", + "successfulNodes": [ + "ecto1.local" + ] +}''' + ).addHeader('content-type', 'application/json') + ); + server.start() + + def retrofit = new Retrofit.Builder().baseUrl(server.url('/api/19/')). + addConverterFactory(JacksonConverterFactory.create()). + build() + def api = retrofit.create(RundeckApi) + + when: + def body = api.getExecution('123').execute().body() + + then: + RecordedRequest request1 = server.takeRequest() + request1.path == '/api/19/execution/123' + + body.dateStarted != null + body.dateStarted.date == '2017-04-13T00:29:19Z' + server.shutdown() + + } }