mirror of
https://github.com/Fishwaldo/rundeck-api-java-client.git
synced 2025-07-18 19:08:21 +00:00
Use builder based arguments for methods
* Replace triggerAdhocScript/Command/Job * Add RunAdhocX interfaces * Add RunJob interface and builder
This commit is contained in:
parent
239b9ea0ee
commit
bbcfd1cff7
13 changed files with 853 additions and 44 deletions
|
@ -28,10 +28,7 @@ import org.rundeck.api.query.ExecutionQuery;
|
|||
import org.rundeck.api.util.PagedResults;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -347,13 +344,13 @@ public class RundeckClientTest {
|
|||
final RundeckJobDelete delete = deleteTest.getResults().get(0);
|
||||
Assert.assertFalse(delete.isSuccessful());
|
||||
Assert.assertNotNull(delete.getError());
|
||||
Assert.assertEquals("unauthorized",delete.getErrorCode());
|
||||
Assert.assertEquals("unauthorized", delete.getErrorCode());
|
||||
Assert.assertNull(delete.getMessage());
|
||||
Assert.assertEquals("3a6d16be-4268-4d26-86a9-cebc1781f768", delete.getId());
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_job_basic")
|
||||
public void triggerJobBasic() throws Exception {
|
||||
public void triggerJobDeprecatedBasic() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test
|
||||
|
@ -366,6 +363,38 @@ public class RundeckClientTest {
|
|||
Assert.assertEquals("admin", test.getStartedBy());
|
||||
Assert.assertEquals(RundeckExecution.ExecutionStatus.RUNNING, test.getStatus());
|
||||
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_job_basic")
|
||||
public void triggerJobBasic() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test
|
||||
= client.triggerJob(RunJobBuilder.builder().setJobId("3170ba0e-6093-4b58-94d2-52988aefbfc9").create());
|
||||
|
||||
Assert.assertEquals((Long) 19L, test.getId());
|
||||
Assert.assertEquals(null, test.getArgstring());
|
||||
Assert.assertEquals(null, test.getAbortedBy());
|
||||
Assert.assertEquals("echo hi there ${job.username} ; sleep 90", test.getDescription());
|
||||
Assert.assertEquals("admin", test.getStartedBy());
|
||||
Assert.assertEquals(RundeckExecution.ExecutionStatus.RUNNING, test.getStatus());
|
||||
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_job_as_user")
|
||||
public void triggerJobDeprecatedAsUser() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test
|
||||
= client.triggerJob("3170ba0e-6093-4b58-94d2-52988aefbfc9", null, null, "api-java-client-user-test1");
|
||||
|
||||
Assert.assertEquals((Long) 20L, test.getId());
|
||||
Assert.assertEquals(null, test.getArgstring());
|
||||
Assert.assertEquals(null, test.getAbortedBy());
|
||||
Assert.assertEquals("echo hi there ${job.username} ; sleep 90", test.getDescription());
|
||||
Assert.assertEquals("api-java-client-user-test1", test.getStartedBy());
|
||||
Assert.assertEquals(RundeckExecution.ExecutionStatus.RUNNING, test.getStatus());
|
||||
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_job_as_user")
|
||||
|
@ -373,7 +402,10 @@ public class RundeckClientTest {
|
|||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test
|
||||
= client.triggerJob("3170ba0e-6093-4b58-94d2-52988aefbfc9",null,null,"api-java-client-user-test1");
|
||||
= client.triggerJob(RunJobBuilder.builder()
|
||||
.setJobId("3170ba0e-6093-4b58-94d2-52988aefbfc9")
|
||||
.setAsUser("api-java-client-user-test1")
|
||||
.create());
|
||||
|
||||
Assert.assertEquals((Long)20L, test.getId());
|
||||
Assert.assertEquals(null, test.getArgstring());
|
||||
|
@ -385,7 +417,7 @@ public class RundeckClientTest {
|
|||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_job_as_user_unauthorized")
|
||||
public void triggerJobAsUserUnauthorized() throws Exception {
|
||||
public void triggerJobDeprecatedAsUserUnauthorized() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test;
|
||||
|
@ -396,10 +428,26 @@ public class RundeckClientTest {
|
|||
Assert.assertEquals("Not authorized for action \"Run as User\" for Job ID 3170ba0e-6093-4b58-94d2-52988aefbfc9", e.getMessage());
|
||||
}
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_job_as_user_unauthorized")
|
||||
public void triggerJobAsUserUnauthorized() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test;
|
||||
try {
|
||||
test = client.triggerJob(RunJobBuilder.builder()
|
||||
.setJobId("3170ba0e-6093-4b58-94d2-52988aefbfc9")
|
||||
.setAsUser("api-java-client-user-test2")
|
||||
.create());
|
||||
Assert.fail("should not succeed");
|
||||
} catch (RundeckApiException e) {
|
||||
Assert.assertEquals("Not authorized for action \"Run as User\" for Job ID 3170ba0e-6093-4b58-94d2-52988aefbfc9", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_command")
|
||||
public void triggerAdhocCommand() throws Exception {
|
||||
public void triggerAdhocCommandDeprecated() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test
|
||||
|
@ -413,9 +461,28 @@ public class RundeckClientTest {
|
|||
Assert.assertEquals(RundeckExecution.ExecutionStatus.SUCCEEDED, test.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_command")
|
||||
public void triggerAdhocCommand() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test
|
||||
= client.triggerAdhocCommand(RunAdhocCommandBuilder.builder()
|
||||
.setProject("test")
|
||||
.setCommand("echo test trigger_adhoc_command")
|
||||
.create());
|
||||
|
||||
Assert.assertEquals((Long) 23L, test.getId());
|
||||
Assert.assertEquals(null, test.getArgstring());
|
||||
Assert.assertEquals(null, test.getAbortedBy());
|
||||
Assert.assertEquals("echo test trigger_adhoc_command", test.getDescription());
|
||||
Assert.assertEquals("admin", test.getStartedBy());
|
||||
Assert.assertEquals(RundeckExecution.ExecutionStatus.SUCCEEDED, test.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_command_as_user")
|
||||
public void triggerAdhocCommandAsUser() throws Exception {
|
||||
public void triggerAdhocCommandDeprecatedAsUser() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test
|
||||
|
@ -429,8 +496,29 @@ public class RundeckClientTest {
|
|||
Assert.assertEquals(RundeckExecution.ExecutionStatus.SUCCEEDED, test.getStatus());
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_command_as_user")
|
||||
public void triggerAdhocCommandAsUser() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test
|
||||
= client.triggerAdhocCommand(
|
||||
RunAdhocCommandBuilder.builder()
|
||||
.setProject("test")
|
||||
.setCommand("echo test trigger_adhoc_command_as_user")
|
||||
.setAsUser("api-java-client-test-run-command-as-user1")
|
||||
.create()
|
||||
);
|
||||
|
||||
Assert.assertEquals((Long) 24L, test.getId());
|
||||
Assert.assertEquals(null, test.getArgstring());
|
||||
Assert.assertEquals(null, test.getAbortedBy());
|
||||
Assert.assertEquals("echo test trigger_adhoc_command_as_user", test.getDescription());
|
||||
Assert.assertEquals("api-java-client-test-run-command-as-user1", test.getStartedBy());
|
||||
Assert.assertEquals(RundeckExecution.ExecutionStatus.SUCCEEDED, test.getStatus());
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_command_as_user_unauthorized")
|
||||
public void triggerAdhocCommandAsUserUnauthorized() throws Exception {
|
||||
public void triggerAdhocCommandDeprecatedAsUserUnauthorized() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test;
|
||||
|
@ -441,7 +529,44 @@ public class RundeckClientTest {
|
|||
Assert.assertEquals("Not authorized for action \"Run as User\" for Run Adhoc", e.getMessage());
|
||||
}
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_command_as_user_unauthorized")
|
||||
public void triggerAdhocCommandAsUserUnauthorized() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
|
||||
final RundeckExecution test;
|
||||
try {
|
||||
test = client.triggerAdhocCommand(
|
||||
RunAdhocCommandBuilder.builder()
|
||||
.setProject("test")
|
||||
.setCommand("echo test trigger_adhoc_command_as_user")
|
||||
.setAsUser("api-java-client-test-run-command-as-user1")
|
||||
.create()
|
||||
);
|
||||
Assert.fail("should not succeed");
|
||||
} catch (RundeckApiException e) {
|
||||
Assert.assertEquals("Not authorized for action \"Run as User\" for Run Adhoc", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_script")
|
||||
public void triggerAdhocScriptDeprecated() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
String script = "#!/bin/bash\n" +
|
||||
"echo test trigger_adhoc_script\n";
|
||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(script.getBytes());
|
||||
|
||||
final RundeckExecution test
|
||||
= client.triggerAdhocScript("test", byteArrayInputStream,(Properties) null, null, null, null, null);
|
||||
|
||||
Assert.assertEquals((Long) 25L, test.getId());
|
||||
Assert.assertEquals(null, test.getArgstring());
|
||||
Assert.assertEquals(null, test.getAbortedBy());
|
||||
Assert.assertEquals("#!/bin/bash\necho test trigger_adhoc_script", test.getDescription());
|
||||
Assert.assertEquals("admin", test.getStartedBy());
|
||||
Assert.assertEquals(RundeckExecution.ExecutionStatus.RUNNING, test.getStatus());
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_script")
|
||||
public void triggerAdhocScript() throws Exception {
|
||||
|
@ -451,7 +576,8 @@ public class RundeckClientTest {
|
|||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(script.getBytes());
|
||||
|
||||
final RundeckExecution test
|
||||
= client.triggerAdhocScript("test", byteArrayInputStream, null, null, null, null, null);
|
||||
= client.triggerAdhocScript(RunAdhocScriptBuilder.builder().setProject("test").setScript
|
||||
(byteArrayInputStream).create());
|
||||
|
||||
Assert.assertEquals((Long) 25L, test.getId());
|
||||
Assert.assertEquals(null, test.getArgstring());
|
||||
|
@ -462,6 +588,24 @@ public class RundeckClientTest {
|
|||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_script_as_user")
|
||||
public void triggerAdhocScriptDeprecatedAsUser() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
String script = "#!/bin/bash\n" +
|
||||
"echo test trigger_adhoc_script\n";
|
||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(script.getBytes());
|
||||
|
||||
final RundeckExecution test
|
||||
= client.triggerAdhocScript("test", byteArrayInputStream, (Properties) null, null, null, null, "api-java-client-test-adhoc-script-as-user1");
|
||||
|
||||
Assert.assertEquals((Long) 26L, test.getId());
|
||||
Assert.assertEquals(null, test.getArgstring());
|
||||
Assert.assertEquals(null, test.getAbortedBy());
|
||||
Assert.assertEquals("#!/bin/bash\necho test trigger_adhoc_script", test.getDescription());
|
||||
Assert.assertEquals("api-java-client-test-adhoc-script-as-user1", test.getStartedBy());
|
||||
Assert.assertEquals(RundeckExecution.ExecutionStatus.RUNNING, test.getStatus());
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_script_as_user")
|
||||
public void triggerAdhocScriptAsUser() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
String script = "#!/bin/bash\n" +
|
||||
|
@ -469,7 +613,8 @@ public class RundeckClientTest {
|
|||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(script.getBytes());
|
||||
|
||||
final RundeckExecution test
|
||||
= client.triggerAdhocScript("test", byteArrayInputStream, null, null, null, null, "api-java-client-test-adhoc-script-as-user1");
|
||||
= client.triggerAdhocScript(RunAdhocScriptBuilder.builder().setProject("test").setScript
|
||||
(byteArrayInputStream).setAsUser("api-java-client-test-adhoc-script-as-user1").create());
|
||||
|
||||
Assert.assertEquals((Long) 26L, test.getId());
|
||||
Assert.assertEquals(null, test.getArgstring());
|
||||
|
@ -480,6 +625,23 @@ public class RundeckClientTest {
|
|||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_script_as_user_unauthorized")
|
||||
public void triggerAdhocScriptDeprecatedAsUserUnauthorized() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
String script = "#!/bin/bash\n" +
|
||||
"echo test trigger_adhoc_script\n";
|
||||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(script.getBytes());
|
||||
|
||||
try{
|
||||
final RundeckExecution test
|
||||
= client.triggerAdhocScript("test", byteArrayInputStream, (Properties) null, null, null, null, "api-java-client-test-adhoc-script-as-user1");
|
||||
Assert.fail("should not succeed");
|
||||
} catch (RundeckApiException e) {
|
||||
Assert.assertEquals("Not authorized for action \"Run as User\" for Run Adhoc", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@Test
|
||||
@Betamax(tape = "trigger_adhoc_script_as_user_unauthorized")
|
||||
public void triggerAdhocScriptAsUserUnauthorized() throws Exception {
|
||||
RundeckClient client = createClient(TEST_TOKEN_3);
|
||||
String script = "#!/bin/bash\n" +
|
||||
|
@ -488,7 +650,8 @@ public class RundeckClientTest {
|
|||
|
||||
try{
|
||||
final RundeckExecution test
|
||||
= client.triggerAdhocScript("test", byteArrayInputStream, null, null, null, null, "api-java-client-test-adhoc-script-as-user1");
|
||||
= client.triggerAdhocScript(RunAdhocScriptBuilder.builder().setProject("test").setScript
|
||||
(byteArrayInputStream).setAsUser("api-java-client-test-adhoc-script-as-user1").create());
|
||||
Assert.fail("should not succeed");
|
||||
} catch (RundeckApiException e) {
|
||||
Assert.assertEquals("Not authorized for action \"Run as User\" for Run Adhoc", e.getMessage());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue