From 0ca7afb1f8cbf990ccb795b4c73d06df4f351552 Mon Sep 17 00:00:00 2001 From: Greg Schueler Date: Wed, 13 Dec 2017 15:50:52 -0800 Subject: [PATCH] Fix #136 parse error with 500 response for project delete --- .../client/api/model/ErrorResponse.java | 2 +- .../client/api/model/ErrorResponseSpec.groovy | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/test/groovy/org/rundeck/client/api/model/ErrorResponseSpec.groovy diff --git a/src/main/java/org/rundeck/client/api/model/ErrorResponse.java b/src/main/java/org/rundeck/client/api/model/ErrorResponse.java index 8e38b14f..2b5a2b3a 100644 --- a/src/main/java/org/rundeck/client/api/model/ErrorResponse.java +++ b/src/main/java/org/rundeck/client/api/model/ErrorResponse.java @@ -35,7 +35,7 @@ public class ErrorResponse implements ErrorDetail { @Attribute public int apiversion; - @Attribute(name = "code") + @Attribute(name = "code", required = false) @Path("error") public String errorCode; diff --git a/src/test/groovy/org/rundeck/client/api/model/ErrorResponseSpec.groovy b/src/test/groovy/org/rundeck/client/api/model/ErrorResponseSpec.groovy new file mode 100644 index 00000000..7277e8ec --- /dev/null +++ b/src/test/groovy/org/rundeck/client/api/model/ErrorResponseSpec.groovy @@ -0,0 +1,54 @@ +package org.rundeck.client.api.model + +import okhttp3.MediaType +import okhttp3.ResponseBody +import retrofit2.Converter +import retrofit2.Retrofit +import retrofit2.converter.jackson.JacksonConverterFactory +import retrofit2.converter.simplexml.SimpleXmlConverterFactory +import spock.lang.Specification + +import java.lang.annotation.Annotation + +/** + * @author greg + * @since 12/13/17 + */ +class ErrorResponseSpec extends Specification { + def "xml parse code not required"() { + given: + def retrofit = new Retrofit.Builder().baseUrl('http://test'). + addConverterFactory(SimpleXmlConverterFactory.create()). + build() + + when: + Converter converter = retrofit.responseBodyConverter( + ErrorResponse.class, + [] as Annotation[], + ); + ErrorResponse result = converter.convert(ResponseBody.create(MediaType.parse('application/xml'), xmlText)) + + then: + + result != null + result.errorCode == code + result.error == error + result.message == message + result.apiVersion == version + + where: + xmlText | + code | + error | + message | version + 'blah' | + null | + 'true' | + 'blah' | 20 + 'blah' | + 'xyz' | + 'true' | + 'blah' | 20 + + } +}