File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\test\java\jenkins\scm\SCMCheckoutStrategyTest.java.html

1 package jenkins.scm;
2
3 import com.gargoylesoftware.htmlunit.html.HtmlPage;
4 import hudson.model.FreeStyleProject;
5 import hudson.model.Item;
6
7 import org.jvnet.hudson.test.HudsonTestCase;
8 import org.jvnet.hudson.test.TestExtension;
9 import hudson.model.AbstractProject;
10 import org.kohsuke.stapler.DataBoundConstructor;
11 import hudson.model.AbstractBuild.AbstractBuildExecution;
12 import org.xml.sax.SAXException;
13
14 import java.io.IOException;
15
16 /**
17 *
18 *
19 * @author Kohsuke Kawaguchi
20 */
21 public class SCMCheckoutStrategyTest extends HudsonTestCase {
22 public void testConfigRoundtrip() throws Exception {
23 assertEquals(1,SCMCheckoutStrategyDescriptor.all().size());
24 FreeStyleProject p = createFreeStyleProject();
25 assertFalse(pageHasUI(p)); // no configuration UI because there's only one option
26 }
27
28 /**
29 * This should show the UI.
30 */
31 public void testConfigRoundtrip2() throws Exception {
32 assertEquals(2,SCMCheckoutStrategyDescriptor.all().size());
33 FreeStyleProject p = createFreeStyleProject();
34 System.out.println(SCMCheckoutStrategyDescriptor.all());
35
36 TestSCMCheckoutStrategy before = new TestSCMCheckoutStrategy();
37 p.setScmCheckoutStrategy(before);
38 configRoundtrip((Item)p);
39 SCMCheckoutStrategy after = p.getScmCheckoutStrategy();
40 assertNotSame(before,after);
41 assertSame(before.getClass(), after.getClass());
42
43 assertTrue(pageHasUI(p));
44 }
45
46 private boolean pageHasUI(FreeStyleProject p) throws IOException, SAXException {
47 HtmlPage page = createWebClient().getPage(p, "configure");
48 return page.getWebResponse().getContentAsString().contains("Advanced Source Code Management");
49 }
50
51 @SuppressWarnings("rawtypes")
52 public static class TestSCMCheckoutStrategy extends SCMCheckoutStrategy {
53 @DataBoundConstructor
54 public TestSCMCheckoutStrategy() {
55 }
56
57 @Override
58 public void checkout(AbstractBuildExecution execution) throws IOException, InterruptedException {
59 execution.getListener().getLogger().println("Hello!");
60 super.checkout(execution);
61 }
62
63 @TestExtension("testConfigRoundtrip2")
64 public static class DescriptorImpl extends SCMCheckoutStrategyDescriptor {
65 @Override
66 public boolean isApplicable(AbstractProject project) {
67 return true;
68 }
69
70 @Override
71 public String getDisplayName() {
72 return getClass().getName();
73 }
74 }
75 }
76 }
77