提交 cd38e863 编写于 作者: K kohsuke

verify that help links work in the configuration page

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15734 71c3de6d-444a-0410-be80-ed276b4c234a
上级 fe4258c5
package hudson.model;
import org.jvnet.hudson.test.HudsonTestCase;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import java.util.List;
import hudson.tasks.Publisher;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.model.HelpLinkTest.HelpNotFoundBuilder.DescriptorImpl;
/**
* Click all the help links and make sure they resolve to some text, not 404.
*
* @author Kohsuke Kawaguchi
*/
public class HelpLinkTest extends HudsonTestCase {
public void testSystemConfig() throws Exception {
clickAllHelpLinks(new WebClient().goTo("configure"));
}
public void testFreestyleConfig() throws Exception {
clickAllHelpLinks(createFreeStyleProject());
}
public void testMavenConfig() throws Exception {
clickAllHelpLinks(createMavenProject());
}
public void testMatrixConfig() throws Exception {
clickAllHelpLinks(createMatrixProject());
}
private void clickAllHelpLinks(Job j) throws Exception {
clickAllHelpLinks(new WebClient().getPage(j,"configure"));
}
private void clickAllHelpLinks(HtmlPage p) throws Exception {
List<?> helpLinks = p.selectNodes("//a[@class='help-button']");
assertTrue(helpLinks.size()>0);
System.out.println("Clicking "+helpLinks.size()+" help links");
for (HtmlAnchor helpLink : (List<HtmlAnchor>)helpLinks)
helpLink.click();
}
public static class HelpNotFoundBuilder extends Builder {
public static final class DescriptorImpl extends BuildStepDescriptor {
public boolean isApplicable(Class jobType) {
return true;
}
@Override
public String getHelpFile() {
return "no-such-file/exists";
}
public String getDisplayName() {
return "I don't have the help file";
}
}
}
/**
* Make sure that this test is meaningful.
* Intentionally put 404 and verify that it's detected.
*/
public void testNegative() throws Exception {
DescriptorImpl d = new DescriptorImpl();
Publisher.all().add(d);
try {
clickAllHelpLinks(createFreeStyleProject());
fail("should detect a failure");
} catch(AssertionError e) {
if(e.getMessage().contains(d.getHelpFile()))
; // expected
else
throw e;
} finally {
Publisher.all().remove(d);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册