KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > taglib > CruiseControlTagSupportTest


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.taglib;
38
39 import java.io.File JavaDoc;
40 import java.io.FileWriter JavaDoc;
41
42 import junit.framework.TestCase;
43 import net.sourceforge.cruisecontrol.mock.MockPageContext;
44 import net.sourceforge.cruisecontrol.mock.MockServletRequest;
45
46 /**
47  *
48  * @author <a HREF="mailto:robertdw@users.sourceforge.net">Robert Watkins</a>
49  */

50 public class CruiseControlTagSupportTest extends TestCase {
51     private CruiseControlTagSupport tag;
52     private MockServletRequest request;
53
54     private String JavaDoc logName1;
55     private String JavaDoc logName2;
56     private String JavaDoc logName3;
57     private File JavaDoc logDir;
58     private File JavaDoc log1;
59     private File JavaDoc log2;
60     private File JavaDoc log3;
61
62     public void setUp() {
63         tag = new CruiseControlTagSupport();
64         MockPageContext pageContext = new MockPageContext();
65         tag.setPageContext(pageContext);
66         request = new MockServletRequest("context", "servlet");
67         pageContext.setHttpServletRequest(request);
68
69         logDir = new File JavaDoc("testresults/");
70         if (!logDir.exists()) {
71             assertTrue("Failed to create test result dir", logDir.mkdir());
72         }
73         logName1 = "log1";
74         logName2 = "log20040905010203Lsuccessful-build-file.1";
75         logName3 = "log20051021142446";
76         log1 = new File JavaDoc(logDir, logName1 + ".xml");
77         log2 = new File JavaDoc(logDir, logName2 + ".xml");
78         log3 = new File JavaDoc(logDir, logName3 + ".xml.gz");
79     }
80     
81     public void tearDown() {
82         tag = null;
83         request = null;
84         
85         log1.delete();
86         log2.delete();
87         log3.delete();
88         logDir.delete();
89
90         log1 = null;
91         log2 = null;
92         log3 = null;
93         logDir = null;
94     }
95
96     public void testCreateUrl() {
97         assertEquals("/context/servlet?param=value", tag.createUrl("param", "value"));
98     }
99
100     public void testCreateUrlReplacingParam() {
101         request.addParameter("param", "differentValue");
102         assertEquals("/context/servlet?param=value", tag.createUrl("param", "value"));
103     }
104
105     public void testCreateUrlPreservingParam() {
106         request.addParameter("otherParam", "otherValue");
107         assertEquals("/context/servlet?otherParam=otherValue&param=value", tag.createUrl("param", "value"));
108     }
109
110     public void testCreateUrlPreservingAndReplacingParams() {
111         request.addParameter("otherParam", "otherValue");
112         request.addParameter("param", "differentValue");
113         assertEquals("/context/servlet?otherParam=otherValue&param=value", tag.createUrl("param", "value"));
114     }
115
116     public void testGetXmlFile() throws Exception JavaDoc {
117         writeFile(log2, "");
118         writeFile(log3, "");
119
120         assertEquals(tag.getXMLFile(logDir, "").getName(), logName3);
121         assertEquals(tag.getXMLFile(logDir, logName2).getName(), logName2);
122     }
123
124     private void writeFile(File JavaDoc file, String JavaDoc body) throws Exception JavaDoc {
125         FileWriter JavaDoc writer = new FileWriter JavaDoc(file);
126         writer.write(body);
127         writer.close();
128     }
129 }
130
Popular Tags