KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > CruiseControlConfigPreConfTest


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2001, 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;
38
39 import java.io.File JavaDoc;
40 import java.net.URL JavaDoc;
41 import java.net.URLDecoder JavaDoc;
42
43 import junit.framework.TestCase;
44 import net.sourceforge.cruisecontrol.util.Util;
45
46 import org.jdom.Element;
47
48 public class CruiseControlConfigPreConfTest extends TestCase {
49
50     private CruiseControlConfig config;
51     private File JavaDoc configFile;
52     private File JavaDoc tempDirectory;
53
54     protected void setUp() throws Exception JavaDoc {
55         // Set up a CruiseControl config file for testing
56
URL JavaDoc url = this.getClass().getClassLoader().getResource("net/sourceforge/cruisecontrol/testconfig-preconf.xml");
57         configFile = new File JavaDoc(URLDecoder.decode(url.getPath()));
58         tempDirectory = configFile.getParentFile();
59
60         Element rootElement = Util.loadConfigFile(configFile);
61         config = new CruiseControlConfig();
62         config.configure(rootElement);
63     }
64
65     protected void tearDown() {
66         // The directory "foo" in the system's temporary file location
67
// is created by CruiseControl when using the config file below.
68
// Specifically because of the line:
69
// <log dir='" + tempDirPath + "/foo' encoding='utf-8' >
70
File JavaDoc fooDirectory = new File JavaDoc(tempDirectory, "foo");
71         fooDirectory.delete();
72     }
73
74     public void testGetProjectNames() {
75         assertEquals(6, config.getProjectNames().size());
76     }
77
78     /*
79     public void testPluginConfiguration() throws Exception {
80         ProjectConfig projConfig = config.getConfig("project4");
81         PluginRegistry plugins = config.getProjectPlugins("project4");
82
83         assertEquals(ListenerTestPlugin.class, plugins.getPluginClass("testlistener"));
84         assertEquals(ListenerTestNestedPlugin.class, plugins.getPluginClass("testnested"));
85         assertEquals(ListenerTestSelfConfiguringPlugin.class, plugins.getPluginClass("testselfconfiguring"));
86
87         List listeners = projConfig.getListeners();
88         assertEquals(3, listeners.size());
89
90         Listener listener0 = (Listener) listeners.get(0);
91         assertEquals(ListenerTestPlugin.class, listener0.getClass());
92         ListenerTestPlugin testListener0 = (ListenerTestPlugin) listener0;
93         assertEquals("project4-0", testListener0.getString());
94
95         Listener listener1 = (Listener) listeners.get(1);
96         assertEquals(ListenerTestPlugin.class, listener1.getClass());
97         ListenerTestPlugin testListener1 = (ListenerTestPlugin) listener1;
98         assertEquals("listener1", testListener1.getString());
99         assertEquals("wrapper1", testListener1.getStringWrapper().getString());
100
101         Listener listener2 = (Listener) listeners.get(2);
102         assertEquals(ListenerTestPlugin.class, listener2.getClass());
103         ListenerTestPlugin testListener2 = (ListenerTestPlugin) listener2;
104         assertEquals("listener2", testListener2.getString());
105         // note this is in fact undefined behavior!! Because we added twice the stringwrapper
106         // (first for the child, then for the parent).
107         // this could probably fail depending on a different platform, except if Element.setContent()
108         // specifies the order in which children are kept within the element.
109         final String wrapper = testListener2.getStringWrapper().getString();
110         assertTrue("wrapper2-works!", "wrapper2-works!".equals(wrapper)
111                                       || "wrapper1".equals(wrapper));
112     }
113
114     public void testPluginConfigurationClassOverride() throws Exception {
115         ProjectConfig projConfig = config.getConfig("project5");
116         PluginRegistry plugins = config.getProjectPlugins("project5");
117
118         assertEquals(ListenerTestPlugin.class, plugins.getPluginClass("testlistener"));
119         assertEquals(ListenerTestOtherNestedPlugin.class, plugins.getPluginClass("testnested"));
120
121         List listeners = projConfig.getListeners();
122         assertEquals(1, listeners.size());
123
124         Listener listener0 = (Listener) listeners.get(0);
125         assertEquals(ListenerTestPlugin.class, listener0.getClass());
126         ListenerTestPlugin testListener0 = (ListenerTestPlugin) listener0;
127         assertEquals("default", testListener0.getString());
128         ListenerTestNestedPlugin nested = testListener0.getNested();
129         assertTrue(nested instanceof ListenerTestOtherNestedPlugin);
130         assertEquals("notshadowing", ((ListenerTestOtherNestedPlugin) nested).getString());
131         assertEquals(null, ((ListenerTestOtherNestedPlugin) nested).getOtherString());
132         assertEquals("otherother", ((ListenerTestOtherNestedPlugin) nested).getOtherOtherString());
133     }
134     */

135
136 }
137
Popular Tags