Skip to content

Commit

Permalink
Fix tests comments
Browse files Browse the repository at this point in the history
1) change disableScheduledAndDeleteProject method to receive params
2) change api version to the last version.
3) the original test is added in the where and if it matches with false.
Additional: Add groovy docs
  • Loading branch information
avelasquezr committed Mar 13, 2024
1 parent 664d668 commit 23b2426
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,11 @@ class ExecutionSpec extends BaseContainer {
jsonValue(response4.body()).executions.size() >= 1
}
cleanup:
(2..4).each {disableScheduledAndDeleteProject("${projectNameSuffix}-${it}")}
(2..4).each {disableScheduledAndDeleteProject("${projectNameSuffix}-${it}", [
"project.disable.schedule": "true",
"project.later.schedule.enable": "false",
"project.disable.executions": "true"
])}
}

def "executions-running when project is disabled"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ProjectUtils {
* @param client The RdClient object used to interact with the Rundeck API.
* @throws RuntimeException If failed to create a project.
*/
public static def createProjectsWithJobsScheduled = (String suffixProjectName, int projectsCount, int jobsCountsPerProject, RdClient client) -> {
static void createProjectsWithJobsScheduled(String suffixProjectName, int projectsCount, int jobsCountsPerProject, RdClient client) {
(1..projectsCount).each {it ->
def projectName = "${suffixProjectName}-${it}".toString()
def getProject = client.doGet("/project/${projectName}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,39 @@ abstract class BaseContainer extends Specification implements ClientProvider {
}
}

/**
* Deletes the specified project.
* This method sends a DELETE request to remove the project with the given name.
* If the deletion operation fails, a RuntimeException is thrown.
*
* @param projectName the name of the project to be deleted. Must not be null.
* @throws RuntimeException if the project deletion fails.
* The exception contains a detailed message obtained from the server's response.
*/
void deleteProject(String projectName) {
def response = client.doDelete("/project/${projectName}")
if (!response.successful) {
throw new RuntimeException("Failed to delete project: ${response.body().string()}")
}
}

void disableScheduledAndDeleteProject(String projectName) {
def responseDisable = client.doPutWithJsonBody("/project/${projectName}/config",
["project.name": projectName, "project.disable.schedule": "true", "project.later.schedule.enable": "false",
"project.disable.executions": "true"])
/**
* Disables scheduled executions for a specific project and then deletes the project.
* This method first makes a PUT request to update the project's configuration,
* specifically to disable all scheduled executions. If this operation is successful,
* it proceeds to delete the project with a DELETE request. If any of the operations fail,
* a RuntimeException is thrown.
*
* @param projectName the name of the project to be disabled and deleted. Must not be null.
* @param body a map containing the configuration to be updated in the project before deletion.
* Specifically, this map should include the necessary properties to disable
* scheduled executions. The exact contents of the map will depend on the client API and
* the project configuration.
* @throws RuntimeException if disabling scheduled executions or deleting the project fails.
* The exception contains a detailed message obtained from the server's response.
*/
void disableScheduledAndDeleteProject(String projectName, Map body) {
def responseDisable = client.doPutWithJsonBody("/project/${projectName}/config", body)
if (!responseDisable.successful) {
throw new RuntimeException("Failed to disable scheduled execution: ${responseDisable.body().string()}")
}
Expand All @@ -328,6 +350,14 @@ abstract class BaseContainer extends Specification implements ClientProvider {
startEnvironment()
}

/**
* Pauses the execution for a specified number of seconds.
* This method utilizes the sleep function to pause the current thread for the given duration.
* If the thread is interrupted while sleeping, it catches the InterruptedException and logs the error.
*
* @param seconds the number of seconds to pause the execution. This value should be positive.
* @throws IllegalArgumentException if the `seconds` parameter is negative, as `Duration.ofSeconds` cannot process negative values.
*/
void hold(int seconds) {
try {
sleep Duration.ofSeconds(seconds).toMillis()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2721,7 +2721,7 @@ class MenuControllerSpec extends RundeckHibernateSpec implements ControllerUnitT
}

params.project = 'project1,project2,project3'
request.api_version = 35
request.api_version = 47

when:
def result = controller.apiExecutionsRunningv14()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ class ApiProjectSelectInterceptorSpec extends Specification implements Intercept

where:
project | controller | action | match
'xProject' | 'menu' | 'apiExecutionsRunningv14' | false
'*' | 'menu' | 'apiExecutionsRunningv14' | false
'***' | 'menu' | 'apiExecutionsRunningv14' | false
'*Project' | 'menu' | 'apiExecutionsRunningv14' | false
'*Project' | 'anyMenu' | 'anyAction' | true
}

void "excluded project"() {
given:
params.project = 'project1'
request.requestURI >> '/api/15/executions/running'
request.requestURI >> '/api/47/executions/running'
request.getMethod() >> 'GET'

when:
Expand Down

0 comments on commit 23b2426

Please sign in to comment.