KickJava   Java API By Example, From Geeks To Geeks.

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


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 net.sourceforge.jwebunit.WebTestCase;
48 import net.sourceforge.cruisecontrol.Configuration;
49
50 import org.jdom.JDOMException;
51
52 public class ProjectConfigurationPageWebTest extends WebTestCase {
53     private static final String JavaDoc CONFIG_URL = "/cruisecontrol/config.jspa?project=connectfour";
54     private static final String JavaDoc CONTENTS_URL = "/cruisecontrol/contents.jspa?project=connectfour";
55     private final String JavaDoc contents;
56     private Configuration configuration;
57
58     public ProjectConfigurationPageWebTest() throws MalformedObjectNameException JavaDoc, IOException JavaDoc,
59             AttributeNotFoundException JavaDoc, InstanceNotFoundException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc, JDOMException {
60         configuration = createConfig();
61         contents = configuration.getConfiguration();
62     }
63
64     protected void setUp() throws Exception JavaDoc {
65         super.setUp();
66         getTestContext().setBaseUrl("http://localhost:7854");
67         configuration = createConfig();
68     }
69
70     protected void tearDown() throws Exception JavaDoc {
71         super.tearDown();
72         configuration.setConfiguration(contents);
73         configuration.save();
74     }
75
76     public void testShouldLinkToRawXMLConfigurationData() {
77         beginAt(CONFIG_URL);
78         assertLinkPresentWithImage("xml.png");
79         clickLinkWithImage("xml.png");
80         assertTitleEquals("CruiseControl Raw XML Configuration");
81     }
82
83     public void testShouldLinkBackToMainPage() {
84         beginAt(CONTENTS_URL);
85         assertLinkPresentWithText("Return to configuration editor");
86         clickLinkWithText("Return to configuration editor");
87         assertFormPresent("reload-configuration");
88     }
89
90     public void testShouldReloadConfiguration() throws Exception JavaDoc {
91         testLoad();
92         gotoPage(CONFIG_URL);
93         setWorkingForm("reload-configuration");
94         submit();
95         assertTextPresent("Reloaded configuration");
96         assertTextNotPresent("Hello, world!");
97     }
98
99     public void testShouldLoadRawXMLConfigurationData() {
100         beginAt(CONTENTS_URL);
101         assertFormPresent("project-configuration");
102         assertFormElementPresent("contents");
103         assertTextPresent("<cruisecontrol>");
104         assertTextPresent("</cruisecontrol>");
105     }
106
107     public void testShouldSaveChangesToXMLConfigurationData() throws Exception JavaDoc {
108         beginAt(CONTENTS_URL);
109         setWorkingForm("project-configuration");
110         setFormElement("contents", contents + "<!-- Hello, world! -->");
111         submit();
112         assertFormPresent("project-configuration");
113         assertFormElementPresent("contents");
114         assertTextPresent("&lt;cruisecontrol&gt;");
115         assertTextPresent("&lt;/cruisecontrol&gt;");
116         assertTextPresent("&lt;!-- Hello, world! --&gt;");
117     }
118
119     public void testLoad() throws Exception JavaDoc {
120         String JavaDoc newContent = "&lt;!-- Hello, world! --&gt;";
121
122         beginAt(CONTENTS_URL);
123         assertFormPresent("project-configuration");
124         setWorkingForm("project-configuration");
125         setFormElement("contents", contents + "<!-- Hello, world! -->");
126         submit();
127         assertFormPresent("project-configuration");
128         assertFormElementPresent("contents");
129         assertTextPresent("&lt;cruisecontrol&gt;");
130         assertTextPresent("&lt;/cruisecontrol&gt;");
131         assertTextPresent(newContent);
132     }
133
134     private static Configuration createConfig() throws IOException JavaDoc, MalformedObjectNameException JavaDoc {
135         return new Configuration("localhost", 7856);
136     }
137 }
138
Popular Tags