File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\main\java\org\jvnet\hudson\test\recipes\LocalData.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.junit.runner.Description;
27 import org.jvnet.hudson.test.HudsonTestCase;
28 import org.jvnet.hudson.test.JenkinsRule;
29 import org.jvnet.hudson.test.HudsonHomeLoader.Local;
30 import org.jvnet.hudson.test.JenkinsRecipe;
31
32 import hudson.util.JenkinsReloadFailed;
33
34 import java.lang.annotation.Documented;
35 import java.lang.annotation.Target;
36 import java.lang.annotation.Retention;
37 import static java.lang.annotation.RetentionPolicy.RUNTIME;
38 import static java.lang.annotation.ElementType.METHOD;
39
40 /**
41 * Runs a test case with a data set local to test method or the test class.
42 *
43 * <p>
44 * This recipe allows your test case to start with the preset <tt>JENKINS_HOME</tt> data loaded
45 * either from your test method or from the test class.
46 *
47 * <p>
48 * For example, if the test method if <tt>org.acme.FooTest.testBar()</tt>, then
49 * you can have your test data in one of the following places in resources folder
50 * (typically <tt>src/test/resources</tt>):
51 *
52 * <ol>
53 * <li>
54 * Under <tt>org/acme/FooTest/testBar</tt> directory (that is, you'll have
55 * <tt>org/acme/FooTest/testBar/config.xml</tt>), in the same layout as in the real <tt>JENKINS_HOME</tt> directory.
56 * <li>
57 * In <tt>org/acme/FooTest/testBar.zip</tt> as a zip file.
58 * <li>
59 * Under <tt>org/acme/FooTest</tt> directory (that is, you'll have
60 * <tt>org/acme/FooTest/config.xml</tt>), in the same layout as in the real <tt>JENKINS_HOME</tt> directory.
61 * <li>
62 * In <tt>org/acme/FooTest.zip</tt> as a zip file.
63 * </ol>
64 *
65 * <p>
66 * Search is performed in this specific order. The fall back mechanism allows you to write
67 * one test class that interacts with different aspects of the same data set, by associating
68 * the dataset with a test class, or have a data set local to a specific test method.
69 *
70 * <p>
71 * The choice of zip and directory depends on the nature of the test data, as well as the size of it.
72 *
73 * @author Kohsuke Kawaguchi
74 */
75 @Documented
76 @Recipe(LocalData.RunnerImpl.class)
77 @JenkinsRecipe(LocalData.RuleRunnerImpl.class)
78 @Target(METHOD)
79 @Retention(RUNTIME)
80 public @interface LocalData {
81 class RunnerImpl extends Recipe.Runner<LocalData> {
82 public void setup(HudsonTestCase testCase, LocalData recipe) throws Exception {
83 testCase.with(new Local(testCase.getClass().getMethod(testCase.getName())));
84 }
85 }
86 class RuleRunnerImpl extends JenkinsRecipe.Runner<LocalData> {
87 public void setup(JenkinsRule jenkinsRule, LocalData recipe) throws Exception {
88 Description desc = jenkinsRule.getTestDescription();
89 jenkinsRule.with(new Local(desc.getTestClass().getMethod(desc.getMethodName())));
90 }
91 }
92 }
93