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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc.
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;
25
26 import hudson.cli.CLICommand;
27 import junit.framework.TestSuite;
28
29 import java.io.File;
30 import java.util.Map;
31
32 /**
33 * Called by the code generated by maven-hpi-plugin to build tests for plugins.
34 *
35 * @author Kohsuke Kawaguchi
36 */
37 public class PluginAutomaticTestBuilder {
38 /**
39 * @param params
40 * Various information about the plugin that maven-hpi-plugin adds.
41 * As of 1.52, this includes the followings:
42 *
43 * basedir (String) : directory that contains pom.xml
44 * artifactId (String) : artifact ID of the plugin
45 * outputDirectory (String) : target/classes dir where class files and resources can be found
46 * testOutputDirectory (String) : target/test-classes.
47 */
48 public static TestSuite build(Map<String,?> params) throws Exception {
49 TestSuite suite = new TestSuite();
50
51 // automatic Jelly tests
52 if (params.containsKey("outputDirectory") // shouldn't happen, but be defensive
53 || notSkipTests("JellyTest")) {
54 File outputDirectory = new File((String)params.get("outputDirectory"));
55 suite.addTest(JellyTestSuiteBuilder.build(outputDirectory,toBoolean(params.get("requirePI"))));
56 }
57
58 suite.addTestSuite(CliSanityTest.class);
59
60 return suite;
61 }
62
63 private static boolean toBoolean(Object requirePI) {
64 if (requirePI==null) return false;
65 if (requirePI instanceof Boolean) return (Boolean)requirePI;
66 return Boolean.parseBoolean(requirePI.toString());
67 }
68
69 /**
70 * Provides an escape hatch for plugin developers to skip auto-generated tests.
71 */
72 private static boolean notSkipTests(String propertyName) {
73 return !Boolean.getBoolean("hpiTest.skip"+propertyName);
74 }
75
76 public static class CliSanityTest extends HudsonTestCase {
77 public void testCliSanity() {
78 CLICommand.clone("help");
79 }
80 }
81 }
82