Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #136 parse error with 500 response for project delete #137

Merged
merged 1 commit into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<ResponseBody, ErrorResponse> 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
'<result error=\'true\' apiversion=\'20\'><error><message>blah</message></error></result>' |
null |
'true' |
'blah' | 20
'<result error=\'true\' apiversion=\'20\'><error code=\'xyz\'><message>blah</message></error></result>' |
'xyz' |
'true' |
'blah' | 20

}
}