KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > sourcecontrols > HttpFileTest


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.sourcecontrols;
38
39 import java.io.File JavaDoc;
40 import java.util.Date JavaDoc;
41 import java.util.List JavaDoc;
42 import java.net.URL JavaDoc;
43
44 import junit.framework.TestCase;
45 import net.sourceforge.cruisecontrol.CruiseControlException;
46 import net.sourceforge.cruisecontrol.Modification;
47
48 public class HttpFileTest extends TestCase {
49
50     public void testValidate() {
51         HttpFile httpFile = new HttpFile();
52
53         try {
54             httpFile.validate();
55             fail("HttpFile should throw when url not set.");
56         } catch (CruiseControlException e) {
57             assertEquals("'url' is required for HttpFile", e.getMessage());
58         }
59
60         httpFile.setURL("Invalid URL");
61         try {
62             httpFile.validate();
63             fail("HttpFile should throw when an invalid URL is provided");
64         } catch (CruiseControlException e) {
65             assertEquals(
66                 "'url' is not a valid connection string : no protocol: Invalid URL",
67                 e.getMessage());
68         }
69     }
70
71     public void testGetModifications() throws Exception JavaDoc {
72         final long timestamp = 100;
73         HttpFile httpFile = new HttpFile() {
74             protected long getURLLastModified(URL JavaDoc url) {
75                 return timestamp;
76             }
77         };
78         httpFile.setURL("http://dummy.domain.net/my/path?que=ry");
79         List JavaDoc modifications = httpFile.getModifications(new Date JavaDoc(1), new Date JavaDoc());
80         assertEquals(1, modifications.size());
81         Modification modif = (Modification) modifications.get(0);
82         assertEquals("my/path?que=ry", modif.getFileName());
83         assertEquals("dummy.domain.net", modif.getFolderName());
84         assertEquals("dummy.domain.net/my/path?que=ry", modif.getFullPath());
85         assertEquals("", modif.comment);
86         assertEquals(timestamp, modif.modifiedTime.getTime());
87         assertEquals("User", modif.userName);
88     }
89
90     public void testGetModificationsInvalidURL() throws Exception JavaDoc {
91         HttpFile httpFile = new HttpFile();
92         File JavaDoc tempFile = File.createTempFile("HttpFileTest", null);
93         tempFile.deleteOnExit();
94         httpFile.setURL(tempFile.toURL().toExternalForm());
95         tempFile.delete();
96         // should not throw with a URL that cannot be connected to
97
httpFile.getModifications(new Date JavaDoc(), new Date JavaDoc());
98     }
99 }
100
Popular Tags