File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\main\java\org\jvnet\hudson\test\recipes\WithTimeout.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 org.jvnet.hudson.test.recipes;
25
26 import org.jvnet.hudson.test.HudsonTestCase;
27 import org.jvnet.hudson.test.JenkinsRecipe;
28 import org.jvnet.hudson.test.JenkinsRule;
29 import org.apache.commons.io.FileUtils;
30
31 import hudson.util.JenkinsReloadFailed;
32
33 import java.io.File;
34 import java.lang.annotation.Documented;
35 import static java.lang.annotation.ElementType.METHOD;
36 import java.lang.annotation.Retention;
37 import static java.lang.annotation.RetentionPolicy.RUNTIME;
38 import java.lang.annotation.Target;
39 import java.net.URL;
40
41 /**
42 * Times out the test after the specified number of seconds.
43 *
44 * All the tests time out after some number of seconds by default, but this recipe
45 * allows you to override that value.
46 *
47 * @author Kohsuke Kawaguchi
48 */
49 @Documented
50 @Recipe(WithTimeout.RunnerImpl.class)
51 @JenkinsRecipe(WithTimeout.RuleRunnerImpl.class)
52 @Target(METHOD)
53 @Retention(RUNTIME)
54 public @interface WithTimeout {
55 /**
56 * Number of seconds.
57 *
58 * 0 to indicate the test should never time out.
59 */
60 int value();
61
62 class RunnerImpl extends Recipe.Runner<WithTimeout> {
63 @Override
64 public void setup(HudsonTestCase testCase, WithTimeout recipe) throws Exception {
65 testCase.timeout = recipe.value();
66 }
67 }
68
69 class RuleRunnerImpl extends JenkinsRecipe.Runner<WithTimeout> {
70 @Override
71 public void setup(JenkinsRule jenkinsRule, WithTimeout recipe) throws Exception {
72 jenkinsRule.timeout = recipe.value();
73 }
74 }
75 }
76