KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > taskdefs > TestFileNames


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: TestFileNames.java,v 1.8 2004/02/01 05:16:33 christianc Exp $
19  */

20 package org.enhydra.barracuda.taskdefs;
21
22 // import junit specifics
23
import junit.framework.TestCase;
24
25 // import logging specifics
26
import org.apache.log4j.Logger;
27
28 // import java specifics
29
import java.io.File JavaDoc;
30 import java.io.IOException JavaDoc;
31
32 import org.enhydra.xml.xmlc.taskdef.*;
33
34 import org.enhydra.barracuda.testbed.*;
35
36 /**
37  * Unit tests for buildFullBaseFileName() and buildClassName() methods
38  * of DefaultXmlcUtilsImpl
39  */

40 public class TestFileNames extends DefaultTestCase {
41
42     //===========================================================================
43
// CONSTRUCTORS
44
//===========================================================================
45

46     /**
47      * Default constructor
48      *
49      * @param theName The name of the test
50      */

51     public TestFileNames( String JavaDoc theName) {
52         super( theName );
53     }
54
55     /**
56      * Sets up the fixture, for example, open a network connection.
57      * This method is called before a test is executed.
58      */

59     protected void setUp() throws Exception JavaDoc {
60         super.setUp();
61     }
62
63     /**
64      * Tears down the fixture, for example, close a network connection.
65      * This method is called after a test is executed.
66      */

67     protected void tearDown() throws Exception JavaDoc {
68         super.tearDown();
69     }
70
71     //===========================================================================
72
// TEST METHODS
73
//===========================================================================
74
public void testBasicBuildFullBaseFileName() throws IOException JavaDoc {
75         XmlcUtils xmlcUtils = XmlcUtils.create();
76
77         String JavaDoc baseFilename = "base";
78         String JavaDoc newBaseFileName = xmlcUtils.buildFullBaseFileName( null, null, baseFilename );
79         assertEquals("Name should be unchanged", baseFilename, newBaseFileName );
80
81         baseFilename = "base.html";
82         String JavaDoc expectedBaseFileName = "base";
83         newBaseFileName = xmlcUtils.buildFullBaseFileName( null, null, baseFilename );
84         assertEquals("Type should be stripped off", expectedBaseFileName, newBaseFileName );
85     }
86
87     public void testPackageNameBuildFullBaseFileName() throws IOException JavaDoc {
88         XmlcUtils xmlcUtils = XmlcUtils.create();
89
90         String JavaDoc baseFilename = "base";
91
92         String JavaDoc packageName = "a";
93         String JavaDoc expectedBaseFileName = "a/" + baseFilename;
94         String JavaDoc newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename );
95         assertEquals("Name 0 should be as expected",
96                      expectedBaseFileName,
97                      newBaseFileName );
98
99         packageName = "";
100         expectedBaseFileName = baseFilename;
101         newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename );
102         assertEquals("Name should be unchanged",
103                      expectedBaseFileName,
104                      newBaseFileName );
105
106         packageName = "a.b.c.d";
107         expectedBaseFileName = "a/b/c/d/" + baseFilename;
108         newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename );
109         assertEquals("Name 1 should be as expected",
110                      expectedBaseFileName,
111                      newBaseFileName );
112
113         packageName = "p1.p2.p3.p4.p5.";
114         expectedBaseFileName = "p1/p2/p3/p4/p5/" + baseFilename;
115         newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename );
116         assertEquals("Name 2 should be as expected",
117                      expectedBaseFileName,
118                      newBaseFileName );
119
120         baseFilename = "/test1/test2/test3/base";
121         packageName = "";
122         expectedBaseFileName = baseFilename;
123         newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename );
124         assertEquals("Name should be unchanged again",
125                      expectedBaseFileName,
126                      newBaseFileName );
127
128         packageName = "a.b.c.d.";
129         expectedBaseFileName = "a/b/c/d" + baseFilename;
130         newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename );
131         assertEquals("Name 3 should be as expected",
132                      expectedBaseFileName,
133                      newBaseFileName );
134     }
135
136     public void testPackageDirBuildFullBaseFileName() throws IOException JavaDoc {
137         XmlcUtils xmlcUtils = XmlcUtils.create();
138
139         String JavaDoc baseFilename = "base";
140         String JavaDoc packageDir = "a";
141         String JavaDoc expectedBaseFileName = "a/" + baseFilename;
142         String JavaDoc newBaseFileName = xmlcUtils.buildFullBaseFileName( null, packageDir, baseFilename );
143         assertEquals("Name 0 should be as expected",
144                      expectedBaseFileName,
145                      newBaseFileName );
146
147         baseFilename = "test.base";
148         packageDir = "";
149         expectedBaseFileName = "test";
150         newBaseFileName = xmlcUtils.buildFullBaseFileName( null, packageDir, baseFilename );
151         assertEquals("Name 1 should be as expected",
152                      expectedBaseFileName,
153                      newBaseFileName );
154
155         baseFilename = "\\base";
156         packageDir = "a/";
157         expectedBaseFileName = "a/" + "base";
158         newBaseFileName = xmlcUtils.buildFullBaseFileName( null, packageDir, baseFilename );
159         assertEquals("Name 2 should be as expected",
160                      expectedBaseFileName,
161                      newBaseFileName );
162
163         baseFilename = "/test1/test2/test3/base";
164         packageDir = "a/b/c/d";
165         expectedBaseFileName = "a/b/c/d/" + "base";
166         newBaseFileName = xmlcUtils.buildFullBaseFileName( null, packageDir, baseFilename );
167         assertEquals("Name 3 should be as expected",
168                      expectedBaseFileName,
169                      newBaseFileName );
170
171         baseFilename = "test1\\test2/test3\\base/";
172         packageDir = "\\a/b\\c/d\\";
173         expectedBaseFileName = "/a/b/c/d/" + "base";
174         newBaseFileName = xmlcUtils.buildFullBaseFileName( null, packageDir, baseFilename );
175         assertEquals("Name 4 should be as expected",
176                      expectedBaseFileName,
177                      newBaseFileName );
178     }
179
180     public void testBuildFullBaseFileName() throws IOException JavaDoc {
181         XmlcUtils xmlcUtils = XmlcUtils.create();
182
183         String JavaDoc baseFilename = "base";
184         String JavaDoc packageName = "packageName";
185         String JavaDoc packageDir = "packageDir";
186         String JavaDoc expectedBaseFileName = packageName + "/" + packageDir + "/" + baseFilename;
187         String JavaDoc newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, packageDir, baseFilename );
188         assertEquals("Name 0 should be as expected",
189                      expectedBaseFileName,
190                      newBaseFileName );
191
192         baseFilename = "/dir1/dir2/dir3/base.test.test";
193         packageName = "name1.name2.name3....";
194         packageDir = "/dirA/dirB/dirc/";
195         expectedBaseFileName = "name1/name2/name3" + packageDir + "base";
196         newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, packageDir, baseFilename );
197         assertEquals("Name 1 should be as expected",
198                      expectedBaseFileName,
199                      newBaseFileName );
200
201         baseFilename = "/dir1/dir2/dir3/base.test.test";
202         packageName = "name1.name2.name3....";
203         packageDir = "";
204         expectedBaseFileName = "name1/name2/name3/" + "dir1/dir2/dir3/base";
205         newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, packageDir, baseFilename );
206         assertEquals("Name 2 should be as expected",
207                      expectedBaseFileName,
208                      newBaseFileName );
209     }
210
211     public void testBuildClassName() throws IOException JavaDoc {
212         XmlcUtils xmlcUtils = XmlcUtils.create();
213
214         String JavaDoc filename = "p1/p2/p3/base";
215         String JavaDoc typeModifier = "HTML";
216         String JavaDoc expectedClassName = "p1.p2.p3.baseHTML";
217         String JavaDoc newClassName = xmlcUtils.buildClassName( filename, typeModifier );
218         assertEquals("Class 0 should be as expected",
219                      expectedClassName,
220                      newClassName );
221     }
222
223
224     //===========================================================================
225
// DATA MEMBERS
226
//===========================================================================
227

228     //===========================================================================
229
// STATIC DATA MEMBERS
230
//===========================================================================
231

232     // setup the loggger for this class
233
private static final Logger theirLogger = Logger.getLogger( TestFileNames.class.getName() );
234
235 }
236
Popular Tags