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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi,
5 * Alan Harder
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25 package hudson;
26
27 import org.jvnet.hudson.test.HudsonTestCase;
28 import org.jvnet.hudson.test.recipes.LocalData;
29
30 import java.net.URL;
31 import java.util.Enumeration;
32
33 /**
34 * @author Alan Harder
35 */
36 public class ClassicPluginStrategyTest extends HudsonTestCase {
37
38 @Override
39 protected void setUp() throws Exception {
40 useLocalPluginManager = true;
41 super.setUp();
42 }
43
44 /**
45 * Test finding resources via DependencyClassLoader.
46 */
47 @LocalData
48 public void testDependencyClassLoader() throws Exception {
49 // Test data has: foo3 depends on foo2,foo1; foo2 depends on foo1
50 // (thus findResources from foo3 can find foo1 resources via 2 dependency paths)
51 PluginWrapper p = jenkins.getPluginManager().getPlugin("foo3");
52 String res = p.getIndexPage().toString();
53 assertTrue(res + "should be foo3", res.contains("/foo3/"));
54
55 // In the current impl, the dependencies are the parent ClassLoader so resources
56 // are found there before checking the plugin itself. Adjust the expected results
57 // below if this is ever changed to check the plugin first.
58 Enumeration<URL> en = p.classLoader.getResources("index.jelly");
59 for (int i = 0; en.hasMoreElements(); i++) {
60 res = en.nextElement().toString();
61 if (i < 2)
62 assertTrue("In current impl, " + res + "should be foo1 or foo2",
63 res.contains("/foo1/") || res.contains("/foo2/"));
64 else
65 assertTrue("In current impl, " + res + "should be foo3", res.contains("/foo3/"));
66 }
67 res = p.classLoader.getResource("index.jelly").toString();
68 assertTrue("In current impl, " + res + " should be foo1 or foo2",
69 res.contains("/foo1/") || res.contains("/foo2/"));
70 }
71 }
72