-
-
Save dwnusbaum/1aee225f6b9a1f262e55e51f98ca4152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.jenkinsci.plugins.workflow.libs; | |
import com.gargoylesoftware.htmlunit.html.DomElement; | |
import com.gargoylesoftware.htmlunit.html.HtmlElement; | |
import com.gargoylesoftware.htmlunit.html.HtmlPage; | |
import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput; | |
import hudson.Util; | |
import hudson.model.Item; | |
import hudson.model.View; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.List; | |
import jenkins.model.Jenkins; | |
import jenkins.plugins.git.GitSCMSource; | |
import jenkins.scm.impl.subversion.SubversionSCMSource; | |
import static org.hamcrest.Matchers.*; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
import org.junit.Rule; | |
import org.jvnet.hudson.test.Issue; | |
import org.jvnet.hudson.test.JenkinsRule; | |
import org.jvnet.hudson.test.MockAuthorizationStrategy; | |
public class GlobalLibrariesTest { | |
@Rule public JenkinsRule r = new JenkinsRule(); | |
@Issue("JENKINS-48516") | |
@Test public void scmVisibility() throws Exception { | |
GlobalLibraries gl = GlobalLibraries.get(); | |
LibraryConfiguration foo = new LibraryConfiguration("foo", new SCMSourceRetriever(new SubversionSCMSource("foo", "https://phony.jenkins.io/foo/"))); | |
LibraryConfiguration bar = new LibraryConfiguration("bar", new SCMSourceRetriever(new GitSCMSource(null, "https://phony.jenkins.io/bar.git", "", "origin", "+refs/heads/*:refs/remotes/origin/*", "*", "", true))); | |
bar.setDefaultVersion("master"); | |
bar.setImplicit(true); | |
bar.setAllowVersionOverride(false); | |
gl.setLibraries(Arrays.asList(foo, bar)); | |
HtmlPage configurePage = r.createWebClient().goTo("configure"); | |
Thread.sleep(5000); | |
System.out.println(configurePage.asXml()); | |
List<DomElement> librariesConfig = configurePage.getElementsByName("libraries"); | |
assertThat(librariesConfig.size(), equalTo(gl.getLibraries().size())); | |
HtmlElement libFoo = (HtmlElement)librariesConfig.get(0); | |
assertInputsSelectedAndDisplayed(libFoo, "Modern SCM", "Subversion"); | |
HtmlElement libBar = (HtmlElement)librariesConfig.get(1); | |
assertInputsSelectedAndDisplayed(libBar, "Modern SCM", "Git"); | |
} | |
private void assertInputsSelectedAndDisplayed(HtmlElement libraryDiv, String retrieverType, String scmType) { | |
boolean matchedRetriever = false; | |
boolean matchedScm = false; | |
for (HtmlElement e : libraryDiv.getElementsByAttribute("input", "type", "radio")) { | |
HtmlRadioButtonInput input = (HtmlRadioButtonInput) e; | |
String label = Util.fixEmptyAndTrim(input.getEnclosingElement("label").getTextContent()); | |
if (!matchedRetriever && retrieverType.equals(label)) { | |
assertTrue(retrieverType + " should be selected", input.isChecked()); | |
assertTrue(retrieverType + " should be visible", input.isDisplayed()); // Should fail before the change, but does not. | |
matchedRetriever = true; | |
continue; | |
} else if (matchedRetriever && !matchedScm && scmType.equals(label)) { | |
assertTrue(scmType + " should be selected", input.isChecked()); | |
assertTrue(scmType + " should be visible", input.isDisplayed()); // Should fail before the change, but does not. | |
matchedScm = true; | |
continue; | |
} | |
assertFalse("Not expecting input to be selected: " + label, input.isChecked()); | |
} | |
assertTrue("Retriever '" + retrieverType + "' was not matched", matchedRetriever); | |
assertTrue("SCM '" + scmType + "' was not matched", matchedScm); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment