Skip to content

Commit

Permalink
New configRoundtrip method for Cloud configuration (#426)
Browse files Browse the repository at this point in the history
* Add new confgRoundtrip method for cloud configuration

* Update src/main/java/org/jvnet/hudson/test/JenkinsRule.java

Co-authored-by: Jesse Glick <[email protected]>

* Improvement after code review

* Update src/main/java/org/jvnet/hudson/test/JenkinsRule.java

Co-authored-by: Jesse Glick <[email protected]>

Co-authored-by: Jesse Glick <[email protected]>
  • Loading branch information
sparsick and jglick authored Apr 22, 2022
1 parent 649c72e commit 9bad176
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
import hudson.security.AbstractPasswordBasedSecurityRealm;
import hudson.security.GroupDetails;
import hudson.security.csrf.CrumbIssuer;
import hudson.slaves.Cloud;
import hudson.slaves.ComputerConnector;
import hudson.slaves.ComputerLauncher;
import hudson.slaves.DumbSlave;
Expand Down Expand Up @@ -180,6 +181,7 @@
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletException;
Expand Down Expand Up @@ -1426,6 +1428,23 @@ public <V extends View> V configRoundtrip(V view) throws Exception {
return view;
}

/**
* Performs a configuration round-trip testing for a cloud.
* The given cloud is added to the cloud list of Jenkins.
* <p>
* If a cloud with the same name already exists, then this old one will be replaced by the given one.
*/
public <C extends Cloud> C configRoundtrip(C cloud) throws Exception {
Cloud cloudConfig = jenkins.getCloud(cloud.name);
if (cloudConfig != null) {
jenkins.clouds.remove(cloudConfig);
}
jenkins.clouds.add(cloud);
jenkins.save();
submit(createWebClient().goTo("configureClouds/").getFormByName("config"));
return (C)jenkins.getCloud(cloud.name);
}


/**
* Asserts that the outcome of the build is a specific outcome.
Expand Down

0 comments on commit 9bad176

Please sign in to comment.