Completed the new extension point.

Adding a test and fixed a broken databinding (because of SCM vs Scm)
This commit is contained in:
Kohsuke Kawaguchi committed 2012-06-05 15:23:09 -07:00
1 parent 9a3f25acbf
commit ddd6867125
4 files changed
+87 -7

No files matched your search

@@ -0,0 +1,73 @@
package jenkins.scm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.model.FreeStyleProject;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.TestExtension;
import hudson.model.AbstractProject;
import org.kohsuke.stapler.DataBoundConstructor;
import hudson.model.AbstractBuild.AbstractBuildExecution;
import org.xml.sax.SAXException;
import java.io.IOException;
/**
*
*
* @author Kohsuke Kawaguchi
*/
public class SCMCheckoutStrategyTest extends HudsonTestCase {
public void testConfigRoundtrip() throws Exception {
assertEquals(1,SCMCheckoutStrategyDescriptor.all().size());
FreeStyleProject p = createFreeStyleProject();
assertFalse(pageHasUI(p)); // no configuration UI because there's only one option
}
/**
* This should show the UI.
*/
public void testConfigRoundtrip2() throws Exception {
assertEquals(2,SCMCheckoutStrategyDescriptor.all().size());
FreeStyleProject p = createFreeStyleProject();
System.out.println(SCMCheckoutStrategyDescriptor.all());
TestSCMCheckoutStrategy before = new TestSCMCheckoutStrategy();
p.setScmCheckoutStrategy(before);
configRoundtrip(p);
SCMCheckoutStrategy after = p.getScmCheckoutStrategy();
assertNotSame(before,after);
assertSame(before.getClass(), after.getClass());
assertTrue(pageHasUI(p));
}
private boolean pageHasUI(FreeStyleProject p) throws IOException, SAXException {
HtmlPage page = createWebClient().getPage(p, "configure");
return page.getWebResponse().getContentAsString().contains("Advanced Source Code Management");
}
public static class TestSCMCheckoutStrategy extends SCMCheckoutStrategy {
@DataBoundConstructor
public TestSCMCheckoutStrategy() {
}
@Override
public void checkout(AbstractBuildExecution execution) throws IOException, InterruptedException {
execution.getListener().getLogger().println("Hello!");
super.checkout(execution);
}
@TestExtension("testConfigRoundtrip2")
public static class DescriptorImpl extends SCMCheckoutStrategyDescriptor {
@Override
public boolean isApplicable(AbstractProject project) {
return true;
}
@Override
public String getDisplayName() {
return getClass().getName();
}
}
}
}