mirror of
https://github.com/Fishwaldo/rundeck-api-java-client.git
synced 2025-07-21 12:29:14 +00:00
Fix issue if history query has no post content
This commit is contained in:
parent
c86a9a1b6e
commit
26f3038bb1
5 changed files with 72 additions and 2 deletions
|
@ -220,6 +220,30 @@ class ApiCall {
|
|||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an HTTP POST or GET request to the RunDeck instance, on the given path, depend ing of the {@link
|
||||
* ApiPathBuilder} contains POST content or not (attachments or Form data). We will login first, and then execute
|
||||
* the API call. At the end, the given parser will be used to convert the response to a more useful result object.
|
||||
*
|
||||
* @param apiPath on which we will make the HTTP request - see {@link ApiPathBuilder}
|
||||
* @param parser used to parse the response
|
||||
*
|
||||
* @return the result of the call, as formatted by the parser
|
||||
*
|
||||
* @throws RundeckApiException in case of error when calling the API
|
||||
* @throws RundeckApiLoginException if the login fails (in case of login-based authentication)
|
||||
* @throws RundeckApiTokenException if the token is invalid (in case of token-based authentication)
|
||||
*/
|
||||
public <T> T postOrGet(ApiPathBuilder apiPath, XmlNodeParser<T> parser) throws RundeckApiException,
|
||||
RundeckApiLoginException,
|
||||
RundeckApiTokenException {
|
||||
if (apiPath.hasPostContent()) {
|
||||
return post(apiPath, parser);
|
||||
} else {
|
||||
return get(apiPath, parser);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an HTTP POST request to the RunDeck instance, on the given path. We will login first, and then execute
|
||||
* the API call. At the end, the given parser will be used to convert the response to a more useful result object.
|
||||
|
|
|
@ -284,4 +284,11 @@ class ApiPathBuilder {
|
|||
public List<NameValuePair> getForm() {
|
||||
return form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if there are any Attachments or Form data for a POST request.
|
||||
*/
|
||||
public boolean hasPostContent() {
|
||||
return getAttachments().size() > 0 || getForm().size() > 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2284,8 +2284,7 @@ public class RundeckClient implements Serializable {
|
|||
.param("max", max)
|
||||
.param("offset", offset);
|
||||
|
||||
|
||||
return new ApiCall(this).post(builder, new HistoryParser("result/events"));
|
||||
return new ApiCall(this).postOrGet(builder, new HistoryParser("result/events"));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -101,6 +101,24 @@ public class RundeckClientTest {
|
|||
Assert.assertEquals(Arrays.asList("fliff", "malk/blah3"), names);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Betamax(tape = "get_history_user",
|
||||
match = {MatchRule.uri, MatchRule.method, MatchRule.path, MatchRule.query })
|
||||
public void getHistoryUser() throws Exception {
|
||||
final RundeckHistory test = client.getHistory("demo", "bob", (String)null, (List)null, null, null, null, null, null);
|
||||
Assert.assertEquals(1, test.getCount());
|
||||
Assert.assertEquals(20, test.getMax());
|
||||
Assert.assertEquals(0, test.getOffset());
|
||||
Assert.assertEquals(1, test.getTotal());
|
||||
final List<RundeckEvent> events = test.getEvents();
|
||||
Assert.assertEquals(1, events.size());
|
||||
final List<String> names = new ArrayList<String>();
|
||||
for (final RundeckEvent event : events) {
|
||||
names.add(event.getUser());
|
||||
}
|
||||
Assert.assertEquals(Arrays.asList("bob"), names);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// not that you can put whatever here, because we don't actually connect to the RunDeck instance
|
||||
|
|
22
src/test/resources/betamax/tapes/get_history_user.yaml
Normal file
22
src/test/resources/betamax/tapes/get_history_user.yaml
Normal file
|
@ -0,0 +1,22 @@
|
|||
!tape
|
||||
name: get_history_user
|
||||
interactions:
|
||||
- recorded: 2012-08-24T21:37:50.531Z
|
||||
request:
|
||||
method: GET
|
||||
uri: http://rundeck.local:4440/api/5/history?project=demo&userFilter=bob
|
||||
headers:
|
||||
Content-Length: '52'
|
||||
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
|
||||
Host: rundeck.localtest:8080
|
||||
Proxy-Connection: Keep-Alive
|
||||
User-Agent: RunDeck API Java Client 5
|
||||
X-RunDeck-Auth-Token: 960412PR40dRREU5d87S2Ce2OeddD5c1
|
||||
response:
|
||||
status: 200
|
||||
headers:
|
||||
Content-Type: text/xml; charset=utf-8
|
||||
Expires: Thu, 01 Jan 1970 00:00:00 GMT
|
||||
Server: Jetty(6.1.21)
|
||||
Set-Cookie: JSESSIONID=118zw5docyvss;Path=/rundeck
|
||||
body: <result success='true' apiversion='5'><events count='1' total='1' max='20' offset='0'><event starttime='1345764091112' endtime='1345764091345'><title>malk/blah2</title><status>succeeded</status><summary>echo aljdsf</summary><node-summary succeeded='1' failed='0' total='1'/><user>bob</user><project>demo</project><date-started>2012-08-23T23:21:31Z</date-started><date-ended>2012-08-23T23:21:31Z</date-ended><job id='fffff'/><execution id='2'/></event></events></result>
|
Loading…
Add table
Add a link
Reference in a new issue