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

1 /*
2 * The MIT License
3 *
4 * Copyright 2012 Jesse Glick.
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
25 package hudson.model;
26
27 import hudson.XmlFile;
28 import java.io.File;
29 import java.util.concurrent.Future;
30 import java.util.regex.Pattern;
31 import static org.junit.Assert.*;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.jvnet.hudson.test.Bug;
35 import org.jvnet.hudson.test.JenkinsRule;
36
37 public class CauseTest {
38
39 @Rule public JenkinsRule j = new JenkinsRule();
40
41 @Bug(14814)
42 @Test public void deeplyNestedCauses() throws Exception {
43 FreeStyleProject a = j.createFreeStyleProject("a");
44 FreeStyleProject b = j.createFreeStyleProject("b");
45 Run<?,?> early = null;
46 Run<?,?> last = null;
47 for (int i = 1; i <= 15; i++) {
48 last = b.scheduleBuild2(0, new Cause.UpstreamCause((Run<?,?>) a.scheduleBuild2(0, last == null ? null : new Cause.UpstreamCause(last)).get())).get();
49 if (i == 5) {
50 early = last;
51 }
52 }
53 String buildXml = new XmlFile(Run.XSTREAM, new File(early.getRootDir(), "build.xml")).asString();
54 assertTrue("keeps full history:\n" + buildXml, buildXml.contains("<upstreamBuild>1</upstreamBuild>"));
55 buildXml = new XmlFile(Run.XSTREAM, new File(last.getRootDir(), "build.xml")).asString();
56 assertFalse("too big:\n" + buildXml, buildXml.contains("<upstreamBuild>1</upstreamBuild>"));
57 }
58
59 @Bug(15747)
60 @Test public void broadlyNestedCauses() throws Exception {
61 FreeStyleProject a = j.createFreeStyleProject("a");
62 FreeStyleProject b = j.createFreeStyleProject("b");
63 FreeStyleProject c = j.createFreeStyleProject("c");
64 Run<?,?> last = null;
65 for (int i = 1; i <= 10; i++) {
66 Cause cause = last == null ? null : new Cause.UpstreamCause(last);
67 Future<? extends Run<?,?>> next1 = a.scheduleBuild2(0, cause);
68 a.scheduleBuild2(0, cause);
69 cause = new Cause.UpstreamCause(next1.get());
70 Future<? extends Run<?,?>> next2 = b.scheduleBuild2(0, cause);
71 b.scheduleBuild2(0, cause);
72 cause = new Cause.UpstreamCause(next2.get());
73 Future<? extends Run<?,?>> next3 = c.scheduleBuild2(0, cause);
74 c.scheduleBuild2(0, cause);
75 last = next3.get();
76 }
77 int count = new XmlFile(Run.XSTREAM, new File(last.getRootDir(), "build.xml")).asString().split(Pattern.quote("<hudson.model.Cause_-UpstreamCause")).length;
78 assertFalse("too big at " + count, count > 100);
79 //j.interactiveBreak();
80 }
81
82 }
83