KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > webtest > ConfigurationTest


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2005 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.webtest;
38
39 import java.io.IOException JavaDoc;
40
41 import javax.management.AttributeNotFoundException JavaDoc;
42 import javax.management.InstanceNotFoundException JavaDoc;
43 import javax.management.MBeanException JavaDoc;
44 import javax.management.MalformedObjectNameException JavaDoc;
45 import javax.management.ReflectionException JavaDoc;
46
47 import junit.framework.TestCase;
48 import net.sourceforge.cruisecontrol.sourcecontrols.ConcurrentVersionsSystem;
49 import net.sourceforge.cruisecontrol.Configuration;
50 import net.sourceforge.cruisecontrol.PluginDetail;
51 import net.sourceforge.cruisecontrol.GenericPluginDetail;
52 import net.sourceforge.cruisecontrol.PluginConfiguration;
53 import net.sourceforge.cruisecontrol.CruiseControlException;
54
55 import org.jdom.JDOMException;
56
57 public class ConfigurationTest extends TestCase {
58     private final String JavaDoc contents;
59     private Configuration configuration;
60
61     public ConfigurationTest() throws MalformedObjectNameException JavaDoc, IOException JavaDoc, AttributeNotFoundException JavaDoc,
62             InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc, JDOMException {
63         configuration = createConfig();
64         contents = configuration.getConfiguration();
65     }
66
67     protected void setUp() throws Exception JavaDoc {
68         super.setUp();
69         configuration = createConfig();
70     }
71
72     protected void tearDown() throws Exception JavaDoc {
73         super.tearDown();
74         configuration.setConfiguration(contents);
75         configuration.save();
76     }
77
78     public void testGetConfiguration() throws Exception JavaDoc {
79         String JavaDoc contents = getContents();
80         String JavaDoc xmlHdr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
81         assertTrue(contents.indexOf(xmlHdr) == 0);
82         assertTrue(contents.indexOf("<cruisecontrol>") != -1);
83         assertTrue(contents.indexOf("</cruisecontrol>") != -1);
84     }
85
86     public void testSetConfiguration() throws Exception JavaDoc {
87         String JavaDoc addContent = "<!-- Hello, world! -->";
88         configuration.setConfiguration(getContents() + addContent);
89         assertTrue(getContents().indexOf(addContent) != -1);
90     }
91
92     public void testCanUpdatePluginConfiguration() throws Exception JavaDoc {
93         String JavaDoc addContent = "projects/foobar";
94         PluginDetail cvsDetail = new GenericPluginDetail("cvs", ConcurrentVersionsSystem.class);
95         PluginConfiguration pluginConfiguration = new PluginConfiguration(cvsDetail, configuration);
96         pluginConfiguration.setDetail("cvsRoot", "projects/foobar");
97         configuration.updatePluginConfiguration(pluginConfiguration);
98         assertTrue(getContents().indexOf(addContent) != -1);
99     }
100
101     public void testGetPluginDetails() throws Exception JavaDoc {
102         PluginDetail[] pluginDetails = configuration.getPluginDetails();
103         assertNotNull(pluginDetails);
104         assertTrue(0 < pluginDetails.length);
105     }
106
107     public void testLoad() throws Exception JavaDoc {
108         String JavaDoc addContent = "<!-- Hello, world! -->";
109         configuration.setConfiguration(getContents() + addContent);
110         configuration.load();
111         assertTrue(getContents().indexOf(addContent) == -1);
112     }
113
114     public void testSave() throws Exception JavaDoc {
115         String JavaDoc addContent = "<!-- Hello, world! -->";
116         configuration.setConfiguration(getContents() + addContent);
117         configuration.save();
118         configuration.load();
119         assertTrue(getContents().indexOf(addContent) != -1);
120     }
121
122     public void testGetConfiguredBootstrappers() throws CruiseControlException, AttributeNotFoundException JavaDoc,
123             InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc, JDOMException {
124         PluginDetail[] bootstrappers = configuration.getConfiguredBootstrappers("connectfour");
125         assertNotNull(bootstrappers);
126         assertTrue(1 == bootstrappers.length);
127     }
128
129     public void testGetConfiguredListeners() throws AttributeNotFoundException JavaDoc, InstanceNotFoundException JavaDoc,
130             MBeanException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc, CruiseControlException, JDOMException {
131         PluginDetail[] listeners = configuration.getConfiguredListeners("connectfour");
132         assertNotNull(listeners);
133         assertTrue(1 == listeners.length);
134     }
135     
136     public void testGetConfiguredSourceControls() throws AttributeNotFoundException JavaDoc, InstanceNotFoundException JavaDoc,
137             MBeanException JavaDoc, ReflectionException JavaDoc, IOException JavaDoc, CruiseControlException, JDOMException {
138         PluginDetail[] sourceControls = configuration.getConfiguredSourceControls("connectfour");
139         assertNotNull(sourceControls);
140         assertTrue(1 == sourceControls.length);
141     }
142
143     private static Configuration createConfig() throws IOException JavaDoc, MalformedObjectNameException JavaDoc {
144         return new Configuration("localhost", 7856);
145     }
146
147     private String JavaDoc getContents() throws AttributeNotFoundException JavaDoc, InstanceNotFoundException JavaDoc, MBeanException JavaDoc,
148             ReflectionException JavaDoc, IOException JavaDoc, JDOMException {
149         return configuration.getConfiguration();
150     }
151 }
152
Popular Tags