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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.model;
25
26 import com.gargoylesoftware.htmlunit.html.HtmlForm;
27 import com.gargoylesoftware.htmlunit.html.HtmlPage;
28 import edu.umd.cs.findbugs.annotations.SuppressWarnings;
29 import hudson.tasks.Builder;
30 import hudson.tasks.Shell;
31 import java.io.ByteArrayInputStream;
32 import org.jvnet.hudson.test.Bug;
33 import org.jvnet.hudson.test.HudsonTestCase;
34
35 import java.util.List;
36 import java.io.File;
37
38 /**
39 * @author Kohsuke Kawaguchi
40 */
41 public class FreeStyleProjectTest extends HudsonTestCase {
42 /**
43 * Tests a trivial configuration round-trip.
44 *
45 * The goal is to catch a P1-level issue that prevents all the form submissions to fail.
46 */
47 public void testConfigSubmission() throws Exception {
48 FreeStyleProject project = createFreeStyleProject();
49 Shell shell = new Shell("echo hello");
50 project.getBuildersList().add(shell);
51
52 // emulate the user behavior
53 WebClient webClient = new WebClient();
54 HtmlPage page = webClient.getPage(project,"configure");
55
56 HtmlForm form = page.getFormByName("config");
57 submit(form);
58
59 List<Builder> builders = project.getBuilders();
60 assertEquals(1,builders.size());
61 assertEquals(Shell.class,builders.get(0).getClass());
62 assertEquals("echo hello",((Shell)builders.get(0)).getCommand().trim());
63 assertTrue(builders.get(0)!=shell);
64 }
65
66 /**
67 * Make sure that the pseudo trigger configuration works.
68 */
69 @Bug(2778)
70 public void testUpstreamPseudoTrigger() throws Exception {
71 pseudoTriggerTest(createMavenProject(), createFreeStyleProject());
72 }
73
74 @Bug(2778)
75 public void testUpstreamPseudoTrigger2() throws Exception {
76 pseudoTriggerTest(createFreeStyleProject(), createFreeStyleProject());
77 }
78
79 @Bug(2778)
80 public void testUpstreamPseudoTrigger3() throws Exception {
81 pseudoTriggerTest(createMatrixProject(), createFreeStyleProject());
82 }
83
84 private void pseudoTriggerTest(AbstractProject up, AbstractProject down) throws Exception {
85 HtmlForm form = new WebClient().getPage(down, "configure").getFormByName("config");
86 form.getInputByName("pseudoUpstreamTrigger").setChecked(true);
87 form.getInputByName("upstreamProjects").setValueAttribute(up.getName());
88 submit(form);
89
90 // make sure this took effect
91 assertTrue(up.getDownstreamProjects().contains(down));
92 assertTrue(down.getUpstreamProjects().contains(up));
93
94 // round trip again and verify that the configuration is still intact.
95 submit(new WebClient().getPage(down, "configure").getFormByName("config"));
96 assertTrue(up.getDownstreamProjects().contains(down));
97 assertTrue(down.getUpstreamProjects().contains(up));
98 }
99
100 /**
101 * Custom workspace and concurrent build had a bad interaction.
102 */
103 @Bug(4206)
104 public void testCustomWorkspaceAllocation() throws Exception {
105 FreeStyleProject f = createFreeStyleProject();
106 File d = createTmpDir();
107 f.setCustomWorkspace(d.getPath());
108 buildAndAssertSuccess(f);
109 }
110
111 /**
112 * Custom workspace and variable expansion.
113 */
114 @Bug(3997)
115 public void testCustomWorkspaceVariableExpansion() throws Exception {
116 FreeStyleProject f = createFreeStyleProject();
117 File d = new File(createTmpDir(),"${JOB_NAME}");
118 f.setCustomWorkspace(d.getPath());
119 FreeStyleBuild b = buildAndAssertSuccess(f);
120
121 String path = b.getWorkspace().getRemote();
122 System.out.println(path);
123 assertFalse(path.contains("${JOB_NAME}"));
124 assertEquals(b.getWorkspace().getName(),f.getName());
125 }
126
127 @Bug(15817)
128 @SuppressWarnings("DM_DEFAULT_ENCODING")
129 public void testMinimalConfigXml() throws Exception {
130 // Make sure it can be created without exceptions:
131 FreeStyleProject project = (FreeStyleProject) jenkins.createProjectFromXML("stuff", new ByteArrayInputStream("<project/>".getBytes()));
132 System.out.println(project.getConfigFile().asString());
133 // and round-tripped:
134 Shell shell = new Shell("echo hello");
135 project.getBuildersList().add(shell);
136 WebClient webClient = new WebClient();
137 HtmlPage page = webClient.getPage(project,"configure");
138 HtmlForm form = page.getFormByName("config");
139 submit(form);
140 List<Builder> builders = project.getBuilders();
141 assertEquals(1,builders.size());
142 assertEquals(Shell.class,builders.get(0).getClass());
143 assertEquals("echo hello",((Shell)builders.get(0)).getCommand().trim());
144 assertTrue(builders.get(0)!=shell);
145 System.out.println(project.getConfigFile().asString());
146 }
147
148 }
149