mirror of
https://github.com/Fishwaldo/rundeck-api-java-client.git
synced 2025-07-08 05:58:39 +00:00
Support v5 bulk delete
This commit is contained in:
parent
76a150c60f
commit
adfcc6393a
13 changed files with 696 additions and 10 deletions
|
@ -30,17 +30,8 @@ import org.apache.commons.io.IOUtils;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
import org.rundeck.api.RundeckApiException.RundeckApiLoginException;
|
||||
import org.rundeck.api.RundeckApiException.RundeckApiTokenException;
|
||||
import org.rundeck.api.domain.RundeckAbort;
|
||||
import org.rundeck.api.domain.RundeckExecution;
|
||||
import org.rundeck.api.domain.RundeckHistory;
|
||||
import org.rundeck.api.domain.RundeckJob;
|
||||
import org.rundeck.api.domain.RundeckJobsImportMethod;
|
||||
import org.rundeck.api.domain.RundeckJobsImportResult;
|
||||
import org.rundeck.api.domain.RundeckNode;
|
||||
import org.rundeck.api.domain.RundeckProject;
|
||||
import org.rundeck.api.domain.RundeckSystemInfo;
|
||||
import org.rundeck.api.domain.*;
|
||||
import org.rundeck.api.domain.RundeckExecution.ExecutionStatus;
|
||||
import org.rundeck.api.domain.RundeckOutput;
|
||||
import org.rundeck.api.parser.*;
|
||||
import org.rundeck.api.query.ExecutionQuery;
|
||||
import org.rundeck.api.util.AssertUtil;
|
||||
|
@ -786,6 +777,24 @@ public class RundeckClient implements Serializable {
|
|||
AssertUtil.notBlank(jobId, "jobId is mandatory to delete a job !");
|
||||
return new ApiCall(this).delete(new ApiPathBuilder("/job/", jobId), new StringParser("result/success/message"));
|
||||
}
|
||||
/**
|
||||
* Delete multiple jobs, identified by the given IDs
|
||||
*
|
||||
* @param jobIds List of job IDS
|
||||
* @return the bulk delete result
|
||||
* @throws RundeckApiException in case of error when calling the API (non-existent job with this ID)
|
||||
* @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)
|
||||
* @throws IllegalArgumentException if the jobId is blank (null, empty or whitespace)
|
||||
*/
|
||||
public RundeckJobDeleteBulk deleteJobs(final List<String> jobIds) throws RundeckApiException, RundeckApiLoginException,
|
||||
RundeckApiTokenException, IllegalArgumentException {
|
||||
if (null == jobIds || 0 == jobIds.size()) {
|
||||
throw new IllegalArgumentException("jobIds are mandatory to delete a job");
|
||||
}
|
||||
return new ApiCall(this).post(new ApiPathBuilder("/jobs/delete").field("ids",jobIds),
|
||||
new BulkDeleteParser("result/deleteJobs"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger the execution of a RunDeck job (identified by the given ID), and return immediately (without waiting the
|
||||
|
|
133
src/main/java/org/rundeck/api/domain/RundeckJobDelete.java
Normal file
133
src/main/java/org/rundeck/api/domain/RundeckJobDelete.java
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* RundeckJobDelete.java
|
||||
*
|
||||
* User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
* Created: 10/1/12 3:53 PM
|
||||
*
|
||||
*/
|
||||
package org.rundeck.api.domain;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* RundeckJobDelete represents a result of a job delete request.
|
||||
*
|
||||
* @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
*/
|
||||
public class RundeckJobDelete {
|
||||
private String id;
|
||||
private String error;
|
||||
private boolean successful;
|
||||
private String errorCode;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* Job ID
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message if the job could not be deleted
|
||||
*/
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(String error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the job was successfully deleted
|
||||
*/
|
||||
public boolean isSuccessful() {
|
||||
return successful;
|
||||
}
|
||||
|
||||
public void setSuccessful(boolean successful) {
|
||||
this.successful = successful;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error code string if there was a failure
|
||||
*/
|
||||
public String getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
public void setErrorCode(String errorCode) {
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Success message if it was successful
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) { return true; }
|
||||
if (o == null || getClass() != o.getClass()) { return false; }
|
||||
|
||||
RundeckJobDelete delete = (RundeckJobDelete) o;
|
||||
|
||||
if (successful != delete.successful) { return false; }
|
||||
if (error != null ? !error.equals(delete.error) : delete.error != null) { return false; }
|
||||
if (errorCode != null ? !errorCode.equals(delete.errorCode) : delete.errorCode != null) { return false; }
|
||||
if (id != null ? !id.equals(delete.id) : delete.id != null) { return false; }
|
||||
if (message != null ? !message.equals(delete.message) : delete.message != null) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id != null ? id.hashCode() : 0;
|
||||
result = 31 * result + (error != null ? error.hashCode() : 0);
|
||||
result = 31 * result + (successful ? 1 : 0);
|
||||
result = 31 * result + (errorCode != null ? errorCode.hashCode() : 0);
|
||||
result = 31 * result + (message != null ? message.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RundeckJobDelete{" +
|
||||
"id='" + id + '\'' +
|
||||
", error='" + error + '\'' +
|
||||
", successful=" + successful +
|
||||
", errorCode='" + errorCode + '\'' +
|
||||
", message='" + message + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* RundeckJobDeleteBulk.java
|
||||
*
|
||||
* User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
* Created: 10/1/12 4:12 PM
|
||||
*
|
||||
*/
|
||||
package org.rundeck.api.domain;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* RundeckJobDeleteBulk represents the result of a bulk job delete request and contains
|
||||
* a list of {@link RundeckJobDelete} objects.
|
||||
*
|
||||
* @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
*/
|
||||
public class RundeckJobDeleteBulk implements Iterable<RundeckJobDelete> {
|
||||
private List<RundeckJobDelete> results;
|
||||
private int requestCount;
|
||||
private boolean allsuccessful;
|
||||
|
||||
public RundeckJobDeleteBulk(List<RundeckJobDelete> results, int requestCount, boolean allsuccessful) {
|
||||
this.results = results;
|
||||
this.requestCount = requestCount;
|
||||
this.allsuccessful = allsuccessful;
|
||||
}
|
||||
|
||||
public List<RundeckJobDelete> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* The number of job delete requests processed.
|
||||
*/
|
||||
public int getRequestCount() {
|
||||
return requestCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if all job delete requests were successful
|
||||
*/
|
||||
public boolean isAllsuccessful() {
|
||||
return allsuccessful;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<RundeckJobDelete> iterator() {
|
||||
if(null!=results){
|
||||
return results.iterator();
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RundeckJobDeleteBulk{" +
|
||||
"results=" + results +
|
||||
", requestCount=" + requestCount +
|
||||
", allsuccessful=" + allsuccessful +
|
||||
'}';
|
||||
}
|
||||
}
|
80
src/main/java/org/rundeck/api/parser/BulkDeleteParser.java
Normal file
80
src/main/java/org/rundeck/api/parser/BulkDeleteParser.java
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* BulkDeleteParser.java
|
||||
*
|
||||
* User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
* Created: 10/1/12 3:55 PM
|
||||
*
|
||||
*/
|
||||
package org.rundeck.api.parser;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.Node;
|
||||
import org.rundeck.api.domain.RundeckJobDelete;
|
||||
import org.rundeck.api.domain.RundeckJobDeleteBulk;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* BulkDeleteParser is ...
|
||||
*
|
||||
* @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
*/
|
||||
public class BulkDeleteParser implements XmlNodeParser<RundeckJobDeleteBulk> {
|
||||
private String xpath;
|
||||
|
||||
public BulkDeleteParser(String xpath) {
|
||||
this.xpath = xpath;
|
||||
}
|
||||
|
||||
public BulkDeleteParser() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RundeckJobDeleteBulk parseXmlNode(Node node) {
|
||||
Node subnode = xpath != null ? node.selectSingleNode(xpath) : node;
|
||||
final ArrayList<RundeckJobDelete> deletes = new ArrayList<RundeckJobDelete>();
|
||||
final List results = subnode.selectNodes("(succeeded|failed)/deleteJobResult");
|
||||
final DeleteParser parser = new DeleteParser();
|
||||
if (null != results && results.size() > 0) {
|
||||
for (final Object o : results) {
|
||||
deletes.add(parser.parseXmlNode((Node) o));
|
||||
}
|
||||
}
|
||||
|
||||
final String requestcount = StringUtils.trimToNull(subnode.valueOf("@requestCount"));
|
||||
final String allsuccessString = StringUtils.trimToNull(subnode.valueOf("@allsuccessful"));
|
||||
int count = 0;
|
||||
boolean allsuccess = false;
|
||||
if (null != requestcount) {
|
||||
try {
|
||||
count = Integer.parseInt(requestcount);
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
}
|
||||
}
|
||||
if (null != allsuccessString) {
|
||||
allsuccess = Boolean.parseBoolean(allsuccessString);
|
||||
}
|
||||
|
||||
return new RundeckJobDeleteBulk(deletes, count, allsuccess);
|
||||
}
|
||||
}
|
63
src/main/java/org/rundeck/api/parser/DeleteParser.java
Normal file
63
src/main/java/org/rundeck/api/parser/DeleteParser.java
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* DeleteParser.java
|
||||
*
|
||||
* User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
* Created: 10/1/12 3:52 PM
|
||||
*
|
||||
*/
|
||||
package org.rundeck.api.parser;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.Node;
|
||||
import org.rundeck.api.domain.RundeckJobDelete;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* DeleteParser is ...
|
||||
*
|
||||
* @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
*/
|
||||
public class DeleteParser implements XmlNodeParser<RundeckJobDelete> {
|
||||
private String xpath;
|
||||
|
||||
public DeleteParser(String xpath) {
|
||||
this.xpath = xpath;
|
||||
}
|
||||
|
||||
public DeleteParser() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RundeckJobDelete parseXmlNode(Node node) {
|
||||
Node resultNode = xpath != null ? node.selectSingleNode(xpath) : node;
|
||||
|
||||
final RundeckJobDelete delete = new RundeckJobDelete();
|
||||
delete.setError(StringUtils.trimToNull(resultNode.valueOf("error")));
|
||||
delete.setErrorCode(StringUtils.trimToNull(resultNode.valueOf("@errorCode")));
|
||||
delete.setId(StringUtils.trimToNull(resultNode.valueOf("@id")));
|
||||
delete.setMessage(StringUtils.trimToNull(resultNode.valueOf("message")));
|
||||
delete.setSuccessful(null == delete.getError() && null == delete.getErrorCode());
|
||||
|
||||
return delete;
|
||||
}
|
||||
}
|
|
@ -29,6 +29,8 @@ import org.junit.Test;
|
|||
import org.rundeck.api.domain.RundeckEvent;
|
||||
import org.rundeck.api.domain.RundeckExecution;
|
||||
import org.rundeck.api.domain.RundeckHistory;
|
||||
import org.rundeck.api.domain.RundeckJobDelete;
|
||||
import org.rundeck.api.domain.RundeckJobDeleteBulk;
|
||||
import org.rundeck.api.domain.RundeckProject;
|
||||
import betamax.Betamax;
|
||||
import betamax.Recorder;
|
||||
|
@ -285,6 +287,60 @@ public class RundeckClientTest {
|
|||
//invalid value for count
|
||||
assertPageResults(test3, 2, -1, -1, -1, -1);
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "bulk_delete")
|
||||
public void bulkDelete() throws Exception {
|
||||
RundeckClient client = new RundeckClient("http://rundeck.local:4440", "PP4s4SdCRO6KUoNPd1D303Dc304ORN87");
|
||||
|
||||
final RundeckJobDeleteBulk deleteTest
|
||||
= client.deleteJobs(Arrays.asList("0ce457b5-ba84-41ca-812e-02b31da355a4"));
|
||||
Assert.assertTrue(deleteTest.isAllsuccessful());
|
||||
Assert.assertEquals(1, deleteTest.getRequestCount());
|
||||
Assert.assertEquals(1, deleteTest.getResults().size());
|
||||
|
||||
final RundeckJobDelete delete = deleteTest.getResults().get(0);
|
||||
Assert.assertTrue(delete.isSuccessful());
|
||||
Assert.assertNull(delete.getError());
|
||||
Assert.assertNull(delete.getErrorCode());
|
||||
Assert.assertNotNull(delete.getMessage());
|
||||
Assert.assertEquals("0ce457b5-ba84-41ca-812e-02b31da355a4", delete.getId());
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "bulk_delete_dne")
|
||||
public void bulkDeleteFailDNE() throws Exception {
|
||||
RundeckClient client = new RundeckClient("http://rundeck.local:4440", "PP4s4SdCRO6KUoNPd1D303Dc304ORN87");
|
||||
|
||||
final RundeckJobDeleteBulk deleteTest
|
||||
= client.deleteJobs(Arrays.asList("does-not-exist"));
|
||||
Assert.assertFalse(deleteTest.isAllsuccessful());
|
||||
Assert.assertEquals(1, deleteTest.getRequestCount());
|
||||
Assert.assertEquals(1, deleteTest.getResults().size());
|
||||
|
||||
final RundeckJobDelete delete = deleteTest.getResults().get(0);
|
||||
Assert.assertFalse(delete.isSuccessful());
|
||||
Assert.assertNotNull(delete.getError());
|
||||
Assert.assertEquals("notfound",delete.getErrorCode());
|
||||
Assert.assertNull(delete.getMessage());
|
||||
Assert.assertEquals("does-not-exist", delete.getId());
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "bulk_delete_unauthorized")
|
||||
public void bulkDeleteFailUnauthorized() throws Exception {
|
||||
RundeckClient client = new RundeckClient("http://rundeck.local:4440", "PP4s4SdCRO6KUoNPd1D303Dc304ORN87");
|
||||
|
||||
final RundeckJobDeleteBulk deleteTest
|
||||
= client.deleteJobs(Arrays.asList("3a6d16be-4268-4d26-86a9-cebc1781f768"));
|
||||
Assert.assertFalse(deleteTest.isAllsuccessful());
|
||||
Assert.assertEquals(1, deleteTest.getRequestCount());
|
||||
Assert.assertEquals(1, deleteTest.getResults().size());
|
||||
|
||||
final RundeckJobDelete delete = deleteTest.getResults().get(0);
|
||||
Assert.assertFalse(delete.isSuccessful());
|
||||
Assert.assertNotNull(delete.getError());
|
||||
Assert.assertEquals("unauthorized",delete.getErrorCode());
|
||||
Assert.assertNull(delete.getMessage());
|
||||
Assert.assertEquals("3a6d16be-4268-4d26-86a9-cebc1781f768", delete.getId());
|
||||
}
|
||||
|
||||
private void assertPageResults(PagedResults<RundeckExecution> jobTest,
|
||||
final int size,
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* BulkDeleteParserTest.java
|
||||
*
|
||||
* User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
* Created: 10/1/12 5:03 PM
|
||||
*
|
||||
*/
|
||||
package org.rundeck.api.parser;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.rundeck.api.domain.RundeckJobDeleteBulk;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* BulkDeleteParserTest is ...
|
||||
*
|
||||
* @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
*/
|
||||
public class BulkDeleteParserTest {
|
||||
@Test
|
||||
public void bulkParser() throws Exception{
|
||||
InputStream input = getClass().getResourceAsStream("delete-job-bulk-test1.xml");
|
||||
Document document = ParserHelper.loadDocument(input);
|
||||
final RundeckJobDeleteBulk deletes = new BulkDeleteParser("result/deleteJobs").parseXmlNode(document);
|
||||
Assert.assertEquals(14, deletes.getRequestCount());
|
||||
Assert.assertEquals(4, deletes.getResults().size());
|
||||
Assert.assertFalse(deletes.isAllsuccessful());
|
||||
}
|
||||
@Test
|
||||
public void bulkParserAllsuccessful() throws Exception{
|
||||
InputStream input = getClass().getResourceAsStream("delete-job-bulk-test2.xml");
|
||||
Document document = ParserHelper.loadDocument(input);
|
||||
final RundeckJobDeleteBulk deletes = new BulkDeleteParser("result/deleteJobs").parseXmlNode(document);
|
||||
Assert.assertEquals(2, deletes.getRequestCount());
|
||||
Assert.assertEquals(2, deletes.getResults().size());
|
||||
Assert.assertTrue(deletes.isAllsuccessful());
|
||||
}
|
||||
}
|
101
src/test/java/org/rundeck/api/parser/DeleteParserTest.java
Normal file
101
src/test/java/org/rundeck/api/parser/DeleteParserTest.java
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright 2012 DTO Labs, Inc. (http://dtolabs.com)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* DeleteParserTest.java
|
||||
*
|
||||
* User: Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
* Created: 10/1/12 4:36 PM
|
||||
*
|
||||
*/
|
||||
package org.rundeck.api.parser;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.dom4j.Document;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.rundeck.api.domain.RundeckAbort;
|
||||
import org.rundeck.api.domain.RundeckExecution;
|
||||
import org.rundeck.api.domain.RundeckJob;
|
||||
import org.rundeck.api.domain.RundeckJobDelete;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* DeleteParserTest is ...
|
||||
*
|
||||
* @author Greg Schueler <a href="mailto:greg@dtosolutions.com">greg@dtosolutions.com</a>
|
||||
*/
|
||||
public class DeleteParserTest {
|
||||
@Test
|
||||
public void successfulResult() throws Exception {
|
||||
InputStream input = getClass().getResourceAsStream("delete-job-bulk-test1.xml");
|
||||
Document document = ParserHelper.loadDocument(input);
|
||||
|
||||
RundeckJobDelete deleteResult = new DeleteParser("result/deleteJobs/succeeded/deleteJobResult[1]").parseXmlNode(document);
|
||||
|
||||
Assert.assertTrue(deleteResult.toString(), deleteResult.isSuccessful());
|
||||
Assert.assertNull(deleteResult.getError());
|
||||
Assert.assertNull(deleteResult.getErrorCode());
|
||||
Assert.assertEquals("test1", deleteResult.getId());
|
||||
Assert.assertEquals("Success", deleteResult.getMessage());
|
||||
}
|
||||
@Test
|
||||
public void failedResult1() throws Exception {
|
||||
InputStream input = getClass().getResourceAsStream("delete-job-bulk-test1.xml");
|
||||
Document document = ParserHelper.loadDocument(input);
|
||||
|
||||
RundeckJobDelete deleteResult = new DeleteParser("result/deleteJobs/failed/deleteJobResult[1]").parseXmlNode(document);
|
||||
|
||||
|
||||
Assert.assertFalse(deleteResult.isSuccessful());
|
||||
Assert.assertEquals("Failed", deleteResult.getError());
|
||||
Assert.assertEquals("failed", deleteResult.getErrorCode());
|
||||
Assert.assertEquals("test2", deleteResult.getId());
|
||||
Assert.assertNull(deleteResult.getMessage());
|
||||
}
|
||||
@Test
|
||||
public void failedResult2() throws Exception {
|
||||
InputStream input = getClass().getResourceAsStream("delete-job-bulk-test1.xml");
|
||||
Document document = ParserHelper.loadDocument(input);
|
||||
|
||||
RundeckJobDelete deleteResult = new DeleteParser("result/deleteJobs/failed/deleteJobResult[2]").parseXmlNode(document);
|
||||
|
||||
|
||||
Assert.assertFalse(deleteResult.isSuccessful());
|
||||
Assert.assertEquals("Unauthorized", deleteResult.getError());
|
||||
Assert.assertEquals("unauthorized", deleteResult.getErrorCode());
|
||||
Assert.assertEquals("test3", deleteResult.getId());
|
||||
Assert.assertNull(deleteResult.getMessage());
|
||||
}
|
||||
@Test
|
||||
public void failedResult3() throws Exception {
|
||||
InputStream input = getClass().getResourceAsStream("delete-job-bulk-test1.xml");
|
||||
Document document = ParserHelper.loadDocument(input);
|
||||
|
||||
RundeckJobDelete deleteResult = new DeleteParser("result/deleteJobs/failed/deleteJobResult[3]").parseXmlNode(document);
|
||||
|
||||
|
||||
Assert.assertFalse(deleteResult.isSuccessful());
|
||||
Assert.assertEquals("Not found", deleteResult.getError());
|
||||
Assert.assertEquals("notfound", deleteResult.getErrorCode());
|
||||
Assert.assertEquals("test4", deleteResult.getId());
|
||||
Assert.assertNull(deleteResult.getMessage());
|
||||
}
|
||||
}
|
24
src/test/resources/betamax/tapes/bulk_delete.yaml
Normal file
24
src/test/resources/betamax/tapes/bulk_delete.yaml
Normal file
|
@ -0,0 +1,24 @@
|
|||
!tape
|
||||
name: bulk_delete
|
||||
interactions:
|
||||
- recorded: 2012-10-02T21:48:08.746Z
|
||||
request:
|
||||
method: POST
|
||||
uri: http://rundeck.local:4440/api/5/jobs/delete
|
||||
headers:
|
||||
Content-Length: '40'
|
||||
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
|
||||
Host: rundeck.local:4440
|
||||
Proxy-Connection: Keep-Alive
|
||||
User-Agent: RunDeck API Java Client 5
|
||||
X-RunDeck-Auth-Token: PP4s4SdCRO6KUoNPd1D303Dc304ORN87
|
||||
body: ''
|
||||
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=g2vkkp7li3rh;Path=/
|
||||
body: '<result success=''true'' apiversion=''5''><deleteJobs requestCount=''1'' allsuccessful=''true''><succeeded count=''1''><deleteJobResult id=''0ce457b5-ba84-41ca-812e-02b31da355a4''><message>Job was successfully deleted: [0ce457b5-ba84-41ca-812e-02b31da355a4]
|
||||
/blah test</message></deleteJobResult></succeeded></deleteJobs></result>'
|
23
src/test/resources/betamax/tapes/bulk_delete_dne.yaml
Normal file
23
src/test/resources/betamax/tapes/bulk_delete_dne.yaml
Normal file
|
@ -0,0 +1,23 @@
|
|||
!tape
|
||||
name: bulk_delete_dne
|
||||
interactions:
|
||||
- recorded: 2012-10-02T21:50:29.756Z
|
||||
request:
|
||||
method: POST
|
||||
uri: http://rundeck.local:4440/api/5/jobs/delete
|
||||
headers:
|
||||
Content-Length: '18'
|
||||
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
|
||||
Host: rundeck.local:4440
|
||||
Proxy-Connection: Keep-Alive
|
||||
User-Agent: RunDeck API Java Client 5
|
||||
X-RunDeck-Auth-Token: PP4s4SdCRO6KUoNPd1D303Dc304ORN87
|
||||
body: ''
|
||||
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=lhr88kmfxmeg;Path=/
|
||||
body: '<result success=''true'' apiversion=''5''><deleteJobs requestCount=''1'' allsuccessful=''false''><failed count=''1''><deleteJobResult id=''does-not-exist'' errorCode=''notfound''><error>Job ID does not exist: does-not-exist</error></deleteJobResult></failed></deleteJobs></result>'
|
|
@ -0,0 +1,23 @@
|
|||
!tape
|
||||
name: bulk_delete_unauthorized
|
||||
interactions:
|
||||
- recorded: 2012-10-02T21:54:20.778Z
|
||||
request:
|
||||
method: POST
|
||||
uri: http://rundeck.local:4440/api/5/jobs/delete
|
||||
headers:
|
||||
Content-Length: '40'
|
||||
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
|
||||
Host: rundeck.local:4440
|
||||
Proxy-Connection: Keep-Alive
|
||||
User-Agent: RunDeck API Java Client 5
|
||||
X-RunDeck-Auth-Token: PP4s4SdCRO6KUoNPd1D303Dc304ORN87
|
||||
body: ''
|
||||
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=1ffmuxzbrwh7o;Path=/
|
||||
body: <result success='true' apiversion='5'><deleteJobs requestCount='1' allsuccessful='false'><failed count='1'><deleteJobResult id='3a6d16be-4268-4d26-86a9-cebc1781f768' errorCode='unauthorized'><error>Not authorized for action "Delete" for Job ID 3a6d16be-4268-4d26-86a9-cebc1781f768</error></deleteJobResult></failed></deleteJobs></result>
|
|
@ -0,0 +1,20 @@
|
|||
<result success='true' apiversion='5'>
|
||||
<deleteJobs requestCount="14" allsuccessful="false">
|
||||
<succeeded>
|
||||
<deleteJobResult id="test1">
|
||||
<message>Success</message>
|
||||
</deleteJobResult>
|
||||
</succeeded>
|
||||
<failed>
|
||||
<deleteJobResult id="test2" errorCode="failed">
|
||||
<error>Failed</error>
|
||||
</deleteJobResult>
|
||||
<deleteJobResult id="test3" errorCode="unauthorized">
|
||||
<error>Unauthorized</error>
|
||||
</deleteJobResult>
|
||||
<deleteJobResult id="test4" errorCode="notfound">
|
||||
<error>Not found</error>
|
||||
</deleteJobResult>
|
||||
</failed>
|
||||
</deleteJobs>
|
||||
</result>
|
|
@ -0,0 +1,12 @@
|
|||
<result success='true' apiversion='5'>
|
||||
<deleteJobs requestCount="2" allsuccessful="true">
|
||||
<succeeded>
|
||||
<deleteJobResult id="test1">
|
||||
<message>Success</message>
|
||||
</deleteJobResult>
|
||||
<deleteJobResult id="test2">
|
||||
<message>Success</message>
|
||||
</deleteJobResult>
|
||||
</succeeded>
|
||||
</deleteJobs>
|
||||
</result>
|
Loading…
Add table
Add a link
Reference in a new issue