KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > builders > MavenScriptTest


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2003, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.builders;
38
39 import java.util.Hashtable JavaDoc;
40
41 import junit.framework.TestCase;
42 import net.sourceforge.cruisecontrol.CruiseControlException;
43 import net.sourceforge.cruisecontrol.testutil.TestUtil;
44
45 import org.apache.log4j.Level;
46 import org.apache.log4j.Logger;
47 import org.apache.log4j.spi.LoggerRepository;
48
49 public class MavenScriptTest extends TestCase {
50
51     /**
52      * String[] getCommandLineArgs(Map, boolean, boolean, boolean, String)
53      * @throws CruiseControlException
54      */

55     public void testGetCommandLineArgs() throws CruiseControlException {
56         MavenScript script = getScript();
57
58         TestUtil.assertArray(
59             "NoDebug:",
60             new String JavaDoc[] {
61             "testmaven.sh",
62             "-Dlabel=200.1.23",
63             "-b",
64             "-p",
65             "testproject.xml" },
66             script.buildCommandline().getCommandline());
67
68         TestUtil.assertArray(
69             "Windows:",
70             new String JavaDoc[] {
71                 "testmaven.sh",
72                 "-Dlabel=200.1.23",
73                 "-b",
74                 "-p",
75                 "testproject.xml" },
76             script.buildCommandline().getCommandline());
77
78         script.setGoalset(" clean jar");
79
80         TestUtil.assertArray(
81             "WithTarget:",
82             new String JavaDoc[] {
83                 "testmaven.sh",
84                 "-Dlabel=200.1.23",
85                 "-b",
86                 "-p",
87                 "testproject.xml",
88                 "clean",
89                 "jar" },
90         // notice the spaces in goalSet
91
script.buildCommandline().getCommandline());
92     }
93
94     private MavenScript getScript() {
95       MavenScript script = new MavenScript();
96       // none should exist for this test
97
script.setMavenScript("testmaven.sh");
98       script.setProjectFile("testproject.xml");
99
100       Hashtable JavaDoc properties = new Hashtable JavaDoc();
101       properties.put("label", "200.1.23");
102       script.setBuildProperties(properties);
103       return script;
104     }
105
106     public void testGetCommandLineArgsWithDebug() throws CruiseControlException {
107       Logger logger = Logger.getLogger(MavenScript.class);
108       LoggerRepository loggerRepository = logger.getLoggerRepository();
109       Level threshold = loggerRepository.getThreshold();
110       Level level = logger.getLevel();
111       
112       loggerRepository.setThreshold(Level.ALL);
113       logger.setLevel(Level.DEBUG);
114       MavenScript script = getScript();
115       TestUtil.assertArray(
116           "WithDebug:",
117           new String JavaDoc[] {
118               "testmaven.sh",
119               "-Dlabel=200.1.23",
120               "-X",
121               "-b",
122               "-p",
123               "testproject.xml" },
124           script.buildCommandline().getCommandline());
125       
126       loggerRepository.setThreshold(threshold);
127       logger.setLevel(level);
128     }
129 }
130
Popular Tags